Basic Queries  «Prev  Next»

Lesson 7 Using DELETE
Objective Delete a row from a table.

Delete table Row using SQL Server

Over time, databases can become very large and result in deteriorating performance. You should plan on periodically taking the time to remove records that have become obsolete or have been inactive for an extended period. This type of spring cleaning will improve performance and reduce storage requirements because there are fewer rows to sort or search through. Reducing the size of the database also frees up disk space that might be needed for something else, such as swap space[1].
Caution should be exercised when deleting data. It's a good idea to archive the data before deleting it from a production database[1] .

Use the DELETE statement to remove rows from a SQL database. The syntax[2] is similar to the SELECT statement except that you do not specify column names since the entire row will be deleted. The following DELETE statement will remove all rows from the BookTable table:

DELETE FROM BookTable
Now you see just how easy it is to remove an entire table of data!
Now let us look at a more practical and less catastrophic example. The book, Maintaining Your Moped, has had poor sales and will no longer be carried by VirtualBookShelf.com.
The following Slide Show describes how the DELETE statement is used to remove only this record from BookTable: 

1) Delete Statement 1 2) Delete Statement 2 3) Delete Statement 3
Program 1 Program 2 Program 3
Using Delete Statement
The next lesson wraps up this module and lets you take a quiz to test your knowledge about basic SQL statements.
[1]swap space or swap file: Disk space used by the operating system to temporarily remove information from main memory.
[2]SQL syntax: Most of the actions you need to perform on a database are done with SQL statements.

[1]production database: A database in use in the production environment.