tailieunhanh - Hướng dẫn học Microsoft SQL Server 2008 part 61
Tuyên bố chấm dứt Các tiêu chuẩn ANSI SQL là đặt một dấu chấm phẩy (;) vào cuối mỗi lệnh để chấm dứt nó. Khi lập trình T-SQL, dấu chấm phẩy sẽ là tùy chọn. Hầu hết các sản phẩm cơ sở dữ liệu khác (bao gồm cả truy cập) để yêu cầu chấm phẩy. Có một vài quy tắc về việc sử dụng dấu chấm phẩy: ■ Không đặt một sau khi một TRY END. ■ Không được đặt một sau khi một điều kiện IF hoặc WHILE. . | Part IV Developing with SQL Server An application can submit a T-SQL batch using ADO or ODBC for execution. A SQL script may be executed by running the SQLCMD command-line utility and passing the SQL script file as a parameter. The SQLCMD utility has several parameters and may be configured to meet nearly any command-line need. T-SQL formatting Throughout this book T-SQL code has been formatted for readability this section specifies the details of formatting T-SQL code. Statement termination The ANSI SQL standard is to place a semicolon at the end of each command in order to terminate it. When programming T-SQL the semicolon is optional. Most other database products including Access do require semicolons. There are a few rules about using the semicolon Don t place one after an END TRY. Don t place one after an IF or WHILE condition. You must place one before any CTE. A statement terminator is required following a MERGE command. Best Practice As a best practice and for improved readability I recommend using the semicolon. In future versions of SQL Server this may become a requirement so making the change now may pay off later. Line continuation T-SQL commands by their nature tend to be long. I have written production queries with multiple joins and subqueries that were a few pages long. I like that T-SQL ignores spaces and end-of-line returns. This smart feature means that long lines can be continued without a special line-continuation character which makes T-SQL code significantly more readable. Comments T-SQL accepts both simple comments and bracketed comments within the same batch. The simple comment begins with two hyphens and concludes with an end-of-line -- This is a simple comment Simple comments may be embedded within a single SQL command 562 Programming with T-SQL 21 SELECT FirstName LastName -- selects the columns FROM Persons -- the source table WHERE LastName LIKE Hal -- the row restriction Management Studio s Query Editor can apply
đang nạp các trang xem trước