III.7.1. Using DML Commands

Data Manipulation Language (DML) commands are used to add, modify, and remove rows from tables. The DML commands can also be referred to as DML statements. The three DML commands supported in SQL Server 2008 are

  • INSERT: Used to add rows to a table. A single INSERT statement can be used to add a single row, or multiple rows.

  • UPDATE: Used to modify data in a table. An UPDATE statement can be used to modify a single column in one or more rows, or multiple columns in multiple rows. The WHERE clause is used to specify which rows to modify. If the WHERE clause is omitted, all the rows in the table will be modified.

  • DELETE: Used to remove rows from a table. A single DELETE statement can be used to remove one or more rows from a table. The WHERE clause is used to specify which rows to modify. If the WHERE clause is omitted, all the rows in the table will be removed.

DML commands can be included within T-SQL batch files or stored procedures. Additionally, DML triggers can be created to respond to each of these DML commands.

For example, an UPDATE DML trigger can be configured on a table to capture and log any changes to the data within the table. Therefore, whenever an UPDATE command is issued against the table, in addition to the UPDATE, the UPDATE trigger will also fire.

Triggers are covered in more depth in Book IV, Chapter 3.

Get Microsoft® SQL Server™ 2008 All-In-One Desk Reference For Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.