Deleting Data and Tables
We often discover that data in a table is incorrect, and therefore can no longer be used. At such times, we need to delete data from a table.
Deleting Values from a Row
Often, we will be interested in deleting a value in a row. The easiest way to accomplish this task is to use the UPDATE
structure we already discussed and to set the column value to NULL
like so:
UPDATE {table_name} SET {column_1} = NULL, Â Â Â Â {column_2} = NULL, Â Â Â Â ... Â Â Â Â {column_last} = NULL WHERE {conditional};
Here, {table_name}
is the name of the table with the data that needs to be changed, {column_1}, {column_2},… {column_last}
is the columns whose values you want to delete, and {WHERE}
is a conditional statement like one you would find in a SQL query.
Let's say, for instance, that we have the wrong email on file for the customer with the customer ID equal to 3
. To fix that, we can use the following...