Chapter 21. Programming with T-SQL
IN THIS CHAPTER
The basics of T-SQL and batches
Working with local variables
Controlling the flow of the batch
Exploring SQL Server objects with code
Working with temporary tables and table variables
Using multiple assignment variable select statements
Standard SQL Data Manipulation Language (DML) commands—
SELECT, INSERT, UPDATE, and
DELETE—only modify or return data. SQL DML lacks both the programming structure to develop procedures and algorithms, and the database-specific commands to control and tune the server. To compensate, each full-featured database product must complement the SQL standard with some proprietary SQL language extension.
Transact-SQL, better known as T-SQL, is Microsoft's implementation of SQL plus its collection of extensions to SQL. The purpose of T-SQL is to provide a set of procedural and administrative tools for the development of a transactional database.
T-SQL is often thought of as synonymous with stored procedures. In reality it's much more than that, which is why this chapter is about T-SQL and the next chapter covers stored procedures. It may be employed in several different ways within a SQL Server client/server application:
T-SQL is used within expressions as part of DML commands (
INSERT, UPDATE, and
DELETE) submitted by the client process.
It is used within blocks of code submitted to SQL Server from a client as a batch or script.
T-SQL functions are used as expressions within check constraints.
T-SQL code is used within ...