T-SQL overview

Source: Internet
Author: User

T-SQL is an enhanced version of the standard SQL programming language and is the primary language used by programs to communicate with SQL Server.

Each SQL statement starts with a predicate (Verb), such as a SELECT or UPDATE keyword. The predicate is followed by one or more clauses (Clause), in which the data that is represented by the predicate or the details of the verb action are given, each beginning with a keyword.

SELECT clauses

1   SELECTclauses2   [into clause]3    fromclauses4   [WHERE clause]5   [GROUP BY clause]6   [Having clause]7   [ORDER BY clause]

Example: in Practice Query in Database Info_stu information about girls in the table

Code:

1    Use Practice 2   Select *  from where Sex='girl'order by age



T-SQL Statement Classification

(1) Variable description statement: The command used to describe the variable;

(2) Data definition statements: Used to create databases, database objects, and definition columns, most of which are commands that start with create , such as create TABLE,create VIEW , and DROP TABLE;

(3) Data manipulation statements: commands used to manipulate data in a database, such as SELECT,INSERT,UPDATE, DELETE and CURSOR , etc.;

(4) Data Control statement: Used to control the database Components access permission, access permissions and other commands, such as GRANT,REVOKE , etc.

(5) Process Control statements: Statements used to design the application flow, such as if while and case;

(6) Inline function: The command that describes the variable;

(7) Other commands: A standard function that is embedded in the command.

Constant

String constants are enclosed in single quotes and contain alphanumeric characters, such as ' man '

Note: If the string in single quotation marks contains an embedded quotation mark, you can use two single quotation marks to represent the embedded single quotation mark.

Variable

Local variables: local variable names must begin with "@"

Declaration of a local variable requires the use of the Declare statement

1 DECLARE 2 {3  @varaible_name[]4 }

Parameter description:

    • @varaible_name: The variable name of the local variable must begin with "@", and the name of the variable must be in the form of the SQL Server identifier;
    • Data_type: The data type used by local variables, which can be all system data types and user-defined data types except text, ntext, or image types.

Declaring local variables

Declare @someone Char (ten)

Assigning values to local variables

There are generally two ways to assign values to local variables, one is to use a select statement, and the other is to use a set statement.

The syntax for assigning a value to a variable using the SELECT statement is as follows:

1   SELECT @varible_name = expression 2    from table_name[,... n]3  WHERE clause

Example: In the Practice Database Info_stu table, the gender is "girl" the information assigned to @someone, and its value with the Print keyword display.

Code:

 use   practice  2  declare   @someone  char  (10  )  3  select   @someone  =  Name from  info_stu where  sex=   " girl   

T-SQL overview

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.