Databases Reference
In-Depth Information
Figure 5-17. The Shippers table after deleting a row
If you try to delete one of the remaining three shippers, you'll get a database error. A
foreign-key relationship exists from Orders (FK) to Shippers (PK), and SSE enforces it,
preventing deletion of Shippers' rows that are referred to by Orders rows. If the database
were to allow you to drop records from the PK table, the records in the FK table would be
left as orphan records, leaving the database in an inconsistent state. (Chapter 3 discusses
keys.)
Sometimes you do need to remove every row from a table. In such cases, the TRUNCATE
TABLE statement may be preferable to the DELETE statement, since it performs better. The
TRUNCATE TABLE statement is faster because it doesn't do any logging (saving each row in a
log file before deleting it) to support recovery, while DELETE logs every row removed.
Summary
In this chapter, you saw how to use the following T-SQL keywords to perform data manip-
ulation tasks against a database: SELECT INTO , SELECT , INSERT , UPDATE , and DELETE . You also
saw how to use comparison and other operators to specify predicates that limit what
rows are retrieved or manipulated.
In the next chapter, you will see how stored procedures work.
Search WWH ::




Custom Search