SQL Server 2012 notes Sharing-46: How to quickly learn T-SQL statements

Source: Internet
Author: User

For beginners, the writing of T-SQL statements has always been a problem, and beginners are accustomed to using the graphical interface to do related SQL maintenance work. But in a slightly more complex and large SQL scenario, if we can quickly grasp and understand the SQL statement writing and use, it will make our operation and maintenance work to achieve a multiplier effect.

In fact, for SQL Server 2012来, it provides a number of ways to help beginners get the corresponding T-SQL scripts for their daily administration tasks. Let's take a few quick examples of getting T-SQL scripts.

====================================================================================================

For example, I created a table in the SQL database in the graphical interface, so how can I quickly get the SQL script to create the table.

650) this.width=650; "title=" clipboard "style=" Border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clipboard "Src=" Http://img1.51cto.com/attachment/201407/1/639838_1404175649iNsR.png "height=" 390 "/> -*+/*-9+ 41520251

We can right-click the database where the table resides, select Tasks, and then choose Generate script.

650) this.width=650; "title=" clipboard[1] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clipboard [1] "src=" http://img1.51cto.com/attachment/201407/1/639838_1404175649Xmhg.png "height=" 586 "/>

On the introduction page, leave the default and choose Next.

650) this.width=650; "title=" clipboard[2] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clipboard [2] "src=" Http://img1.51cto.com/attachment/201407/1/639838_1404175650qHwn.png "height=" 484 "/>

In the Select object interface, tick "Select a specific Database object", then expand the table and select the table table-test01 we want to generate the script.

650) this.width=650; "title=" clipboard[3] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clipboard [3] "src=" Http://img1.51cto.com/attachment/201407/1/639838_14041756507c0P.png "height=" 484 "/>

Then to the Setup scripting options interface, specify how the script should be saved or published, where I save the generated script to the new query window.

650) this.width=650; "title=" clipboard[4] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clipboard [4] "src=" Http://img1.51cto.com/attachment/201407/1/639838_1404175650FcsE.png "height=" 484 "/>

In the summary interface, after confirming that there is no problem, select Next.

650) this.width=650; "title=" clipboard[5] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clipboard [5] "src=" Http://img1.51cto.com/attachment/201407/1/639838_140417565092VL.png "height=" 484 "/>

After the save is successful, click Finish.

650) this.width=650; "title=" clipboard[6] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clipboard [6] "src=" Http://img1.51cto.com/attachment/201407/1/639838_1404175651dmrG.png "height=" 484 "/>

Then we come to the new query window and we can see the generated script information.

650) this.width=650; "title=" clipboard[7] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clipboard [7] "src=" http://img1.51cto.com/attachment/201407/1/639838_1404175651SICH.png "height=" 269 "/>

==========================================================================================

In addition to the above methods, such as data backup. We can get the relevant script of data backup in the GUI.

In the backup database interface, we can select "Script" above and then save the current operation as a script.

650) this.width=650; "title=" clipboard[8] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clipboard [8] "src=" Http://img1.51cto.com/attachment/201407/1/639838_140417565107Td.png "height=" 484 "/>

The script for the generated backup database is as shown in.

650) this.width=650; "title=" clipboard[9] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clipboard [9] "src=" http://img1.51cto.com/attachment/201407/1/639838_1404175652wsoe.png "height=" "/>

=============================================================================================

Similarly, how can we get the script statements for inserting, deleting, updating the table, in fact, this is very simple, but also through the graphical interface to obtain the corresponding script statements, convenient for beginners to learn and use.

650) this.width=650; "title=" clipboard[10] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clipboard [Ten] "src=" http://img1.51cto.com/attachment/201407/1/639838_1404175652gnce.png "height=" 333 "/>

For example, if we choose to update the table, we get the corresponding update script.

650) this.width=650; "title=" clipboard[11] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clipboard [One] "src=" Http://img1.51cto.com/attachment/201407/1/639838_1404175654JkkV.png "height=" 165 "/>

============================================================================================

This article from "Zeng Hung Xin Technical column" blog, declined to reprint!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.