Quick Start for T-SQL statements

Source: Internet
Author: User

At Microsoft official, there is a tutorial on T-SQL statements, very well understood, can help beginners, understand the use of common SQL statements syntax, and do not involve more complex operations, do not install the sample database AdventureWorks. The following is an excerpt of the tutorial's content.

T-SQL, or Transact-SQL, is Microsoft's implementation of the SQL standard. (Description: The following T-SQL statements are written and executed in the Query editor)

1. Create a database TestData

CREATE DATABASE TestData GO

The mouse selected "CREATE DATABASE", press F1, will bring up the "CREATE DATABASE" statement of the online Help document, the mouse selected "CREATE DATABASE TestData" statement, press F5, will execute this statement.

The database created is actually a copy of the model database and the result of replacing the name with TestData.

Note: Go is used to separate statements when there is more than one statement executed, and go can be omitted when there is only one statement.

2. CREATE TABLE Products

The table has a name, and the column has a data type. When you create a table, you typically have a primary key, and the value of the primary key is unique in the table and can be a combination of one or more columns, and it is a good practice to specify whether it can be null for each column.
The default installation of the database engine is case insensitive, meaning that "OrderData" is the same as "OrderData".

2.1. Create a database that holds tables

 UseMaster;--Delete The TestData database if it exists.IF EXISTS(SELECT *  fromsys.databasesWHEREName='TestData')BEGIN    DROP DATABASETestData;END--Create A new database called TestData.CREATE DATABASETestData;

Press F5 to execute the statement.

2.2. Switch the connected database
Using the TestData database

 Use TestData GO


2.3. CREATE TABLE Products

 create  table   dbo. Products (ProductID  int  primary  Span style= "color: #0000ff;" >key  not  null  , ProductName  varchar  ( not  null   money  null   text  Span style= "color: #0000ff;" >null  )  go  

Executes the statement. A table named products was created with 4 columns: ProductID, ProductName, Price, and ProductDescription, with the data types int, varchar (25), Money, and text. The data for the price and ProductDescription columns can be empty. This statement also contains an optional element (dbo.), called a schema, which refers to the database object that owns the table. If you are an administrator, the default schema is DBO, which represents the database owner.

Finish

Quick Start for T-SQL statements

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.