DELETE FROM TableName
WHERE Condition(s)
The TableName factor is used to identify a
table whose record(s) would be removed.
The Condition(s) factor allows you to identify
a record or a group of records that carries a criterion. Make
sure you are precise in your criteria so you would not delete the wrong
record(s).
Here is an example used to remove a particular record from the
table:
private void btnDatabase_Click(object sender, EventArgs e)
{
using (SqlConnection connection =
new SqlConnection("Data Source=(local);" +
"Database='Exercise1';" +
"Integrated Security=yes;"))
{
SqlCommand command =
new SqlCommand("DELETE FROM Videos " +
"WHERE VideoTitle = 'The Lady Killers';",
connection);
connection.Open();
command.ExecuteNonQuery();
}
}
Instead of one, you can delete more than one record at
a time. To programmatically delete a group or records, apply the
DELETE FROM table formula and use a WHERE
condition that can identify each one of the records.
If you think all records of a particular table are, or have
become, useless, you can clear the whole table, which would still keep its
structure.
Using SQL, to clear a table of all records, use the DELETE
operator with the following formula:
DELETE TableName;
When this statement is executed, all records from the TableName
factor would be removed from the table. Be careful when doing this because
once the records have been deleted, you cannot get them back.