Records Maintenance: Deleting Records



Record maintenance includes viewing records, looking for one or more records, modifying one or more records, or deleting one or more records.

If you find out that a record is not necessary, not anymore, or is misplaced, you can remove it from a table. In SQL, to delete a record, use the DELETE FROM statement associated with the WHERE operator. The formula to follow is:

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';",

Deleting Many Records

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.

Deleting all 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.


Home Copyright © 2009-2015, FunctionX, Inc.