8.5. Emptying Tables


To remove records from a table without removing the table itself, use the DELETE or trUNCATE TABLE statement. Either of the following statements completely empties the named table:

 DELETE FROM t; TRUNCATE TABLE t; 

DELETE takes an optional WHERE clause that identifies which records to remove. This is useful when you want to delete only a given subset of records from a table. The following statement removes only those records from t that have a status column value of 'expired':

 DELETE FROM t WHERE status = 'expired'; 

DELETE and trUNCATE TABLE are discussed further in Section 11.5, "The DELETE and TRUNCATE TABLE Statements," where you can find a comparative breakdown of their operational characteristics.



MySQL 5 Certification Study Guide
MySQL 5.0 Certification Study Guide
ISBN: 0672328127
EAN: 2147483647
Year: 2006
Pages: 312

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net