Changes

Jump to: navigation, search

Updating and Deleting MySQL Data

1,172 bytes added, 18:53, 4 October 2007
Updating Database Data
prod_name = 'Big Red Shoes'
WHERE prod_id = 12134;
</pre>
 
== Ignoring Update Errors ==
 
If an UPDATE statements is designed to update multiple row, and an error is encountered attempting to update some of those rows, the entire update is cancelled and any rwos that had been changed are reverted to their original values. Use of the ''IGNORE'' keyword will cause the update to continue, simply skipping any rows which presented an problem:
 
<pre>
UPDATE IGNORE products
SET prod_desc = 'Size 10 Red Shoe',
prod_name = 'Big Red Shoes'
WHERE prod_id = 12134;
</pre>
 
== Delete Database Data ==
 
Either all rows, or only specific rows in a table can be deleted using the SQL ''DELETE'' statement. Once again, this statement can, and indeed should, be used in conjunction with the ''WHERE'' clause. Omission of the ''WHERE'' keyword will result in all rows in a table being deleted. In fact, it is often even recommended that the criteria to be used for the ''WHERE'' filter first be tested with a ''SELECT'' statement to ensure it does exactly what you intended.
 
The following SQL statement removes a row from our products table where the prod_id field is equal 12134:
 
<pre>
DELETE FROM products WHERE prod_id = 12134;
</pre>

Navigation menu