The Delete Statement

 < Day Day Up > 

The Delete Statement

The Delete statement removes rows from a table. Here is its syntax.

Delete From <table>
[Where <expression>]

Where <table> is the name of the table that you wish to update, and <expression> is true for all the rows that should be updated.

You can use the Delete statement to remove one or more rows from a table. Simply specifying Delete From Customers will delete every row from the Customers table. However, this isn’t a good idea unless you really want an empty table. Using the same Where clause in the Select statement lets you limit the number of rows deleted.


If you accidentally delete all the rows from your table, you might be in trouble. Once the rows are deleted, they can’t be undeleted. There isn’t really an Undo function for a database like you find in Excel. Pressing Ctrl+Z will not undo your changes. There are techniques (for example, using transactions) that an advanced database programmer can use to allow you to recover from this type of error, but in general once the rows are deleted, it’s best to assume they’re gone.

This example deletes all the rows that have a DateUpdated value that is earlier than 31 December 2002.

Delete From Customers
Where DateUpdated <= ’31-Dec-2002’

In this chapter, you learned a little bit about how relational databases such as Microsoft Access and Microsoft SQL Server work. You also learned about the Structured Query Language more commonly referred to as SQL. This language defines statements that allow you to retrieve data from a database (Select), add data to a database (Insert), change data in the database (Update), and remove data from the database (Delete).

 < Day Day Up > 

Microsoft Excel 2003 Programming Inside Out
Microsoft Office Excel 2003 Programming Inside Out (Inside Out (Microsoft))
ISBN: 0735619859
EAN: 2147483647
Year: 2006
Pages: 161

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: