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