Adding, Changing, or Removing Data

In SQL Server, you can add, remove, or change data by using the INSERT, DELETE, TRUNCATE TABLE, UPDATE, UPDATETEXT, and WRITETEXT data modification statements.

You can also add data to a table by transferring it from a file using the bulk copy program, bcp. (For information about bcp, see the Microsoft SQL Server Administrator's Companion and the bcp command-line utility in the Microsoft SQL Server Transact-SQL Reference.)

You can modify (INSERT, UPDATE, or DELETE) data in only one table per statement. Transact-SQL lets you base your modifications on data in other tables, even those in other databases.

The data modification statements work on views as well as on tables, with some restrictions. For details, see Using Views in Working with Tables.

Note Most examples in this book refer to the pubs sample database. The pubs sample database is included as a learning tool; it is created when the server is installed. To use the sample database, your system must have access to the pubs database. If you have a localized version of SQL Server and want to try the examples, drop the localized version of pubs and install the U.S. English version of pubs. To install the U.S. English version of pubs, run the INSTPUBS.SQL script with the isql command-line utility. This script can be found in the INSTALL directory of SQL Server. Also, if other users have executed the examples in this chapter, it is likely that the pubs database has been altered. This will change the output you see from some of the examples. You can reinstall the original pubs database at any time by running the INSTPUBS.SQL script.

To run the INSTPUBS.SQL script, from an operating-system prompt, type:

isql /Usa /Ppassword /Sserver -i\sql60\install\instpubs.sql

For details about isql, see the isql command-line utility in the Microsoft SQL Server Transact-SQL Reference.