Talking about Transact-sql_mssql

Source: Internet
Author: User
Tags error handling microsoft sql server sybase

Transact-SQL (also known as T-SQL), an ANSI SQL implementation on Microsoft SQL Server and Sybase, is similar to Oracle's PL/SQL (not just implementing ANSI SQL, also provides implementation support for its own database system features, which are still used as the core query language in Microsoft SQL Server and Sybase Adaptive Server.

Transact-SQL is a collection of data-based with bulk and block attributes that a database developer can use to compose the business logic of the data part (Business Logic) to enforce limits on the ability of front-end applications to control data. At the same time, it is also the main development language of database objects.

Language structure

Transact-SQL is mainly made up of ANSI, and Transact-SQL currently implemented by Microsoft can support the ANSI SQL-92 standard.

ANSI SQL Base Syntax support

Ddl

Main entry: Data definition language

DDL (Data Definition Language) is a control syntax for database objects, which is used for additions, modifications, and deletions to database objects such as datasheets, stored procedures, functions, or custom types.

Create (Creating a Database object) ALTER (Modify Database object) Drop (delete database object)

Dml

Main entry: Data manipulation language

DML (data manipulation Language) is the CRUD (create/retrieve/update/delete) feature commonly known to developers, meaning new/intercepting/modifying/removing four features of data.

SELECT (R) INSERT (C) UPDATE (U) DELETE (D)

DCL

Main entry: Data Control language

DCL (Data Control Language) is a security function provided by the database, and the Access principles and permissions for database and database objects are defined by DCL.

GRANT (Assign permission) REVOKE (revoke permissions) bulk

Transact-SQL can use semicolons ";" to partition different SQL directives. For example:

INSERT into MyTable (myText) VALUES (@myText); SELECT @ @IDENTITY

Control Flow syntax

Transact-SQL can support the following control process syntax (Control-flow):

BEGIN ... End, to indicate the SQL instruction block, using the begin ... End-wrapped instructions are treated as the same instruction block. IF ... else is conditional and can support nested if judgments, if the instruction in if or else contains more than two, you must use the BEGIN ... End to indicate the block, otherwise a syntax check error occurs. While loop, which is the only supported loop in Transact-SQL, the instructions in the loop are used to begin ... End wrapper. Return, which forces the block to terminate its operation. WAITFOR, you can force a statement to wait for a specified time before it continues to run. GOTO, which can be directed to the specified location by running the command. Custom variables

In Transact-SQL, you can use declare to declare variables, set variable values, and use a SELECT @var = column to obtain variable values from a declarative return value.

DECLARE @v INT--DECLARE a variableset @v =--Set variable directly. SELECT @v = SUM (Qty) from saleitemrecords WHERE Saleid = 53928--Set variable from a result of statement

Error handling

Transact-SQL can handle or raise an error in a block by using the following methods:

RAISERROR, throw out a defined error condition. TRY ... CATCH, using structured methods to handle errors (only Transact-SQL support implemented by Microsoft SQL Server). Print, you can print out the value of the variable.

Microsoft Transact-SQL Introduction address: http://msdn.microsoft.com/zh-cn/library/bb510741.aspx

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.