Database Review Summary (-T-SQL) programming

Source: Internet
Author: User
Tags microsoft sql server

T-SQL (SQL SERVER)

Baidu Encyclopedia: (that is, Transact-SQL, is an enhanced version on Microsoft SQL Server, it is the primary language used to make applications communicate with SQL Server.) T-SQL provides DDL and DML functionality for standard SQL, plus extended functions, system stored procedures, and program design constructs (such as IF and while) to make programming more resilient.

(1) Variables
-"declaration: Declare variable name type--variable name required to start with @
-"Settings: Set/select variable name = value
-"Output: Print/select variable name
-"Global variables: Using the double @ symbol, system built-in variables
@ @version--database version
@ @identity-called after inserting, returns the most-Pro identity value
@ @servername-server name
@ @error-Returns the error number of the last Transact-SQL statement executed and returns 0 if there are no errors
@ @rowcount-Returns the number of rows affected by the previous statement
(2) SELECT statement if

(3) Loop statement while (this only one)


(4) Exception handling statements
Begin Try...end Try
Begin Catch...end Catch

-- 1. Variables Declare @name nvarchar (ten) -- Statement Set @name = ' Wuhan University ' -- Assign Value Print @name -- Output
View Code
--SELECT statementDeclare @id intSet @id=Tenif @id>5begin    --when the condition is met, execute the following code    Print 'OK'EndElsebegin    --when the condition is not met, execute the following code    Print 'No'End--LoopsDeclare @id intSet @id=1 while @id<Tenbegin    Print @id    Set @id=@id+1End--all even numbers between output 1-10Declare @num intSet @num=1 while @num< Onebegin    if @num%2=0    begin        Print @num    End    Set @num=@num+1End--Exception HandlingbeginTryDelete  fromClassInfoEndTrybeginCatchPrint @ @errorEndCatch
View Code

Database Review Summary (-T-SQL) programming

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.