Deleting Data in MySQL

By: Sathya Narayana Emailed: 1729 times Printed: 2338 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

To delete a given row or set of rows, you use the DELETE FROM...WHERE command. For instance, you can delete the book called Mr Bunny's Guide to JDO with this command:

mysql> DELETE FROM book
          -> WHERE title = "Mr Bunny's Guide to JDO";

Now execute a SELECT command to retrieve all books from the table, and you'll see that the record for that book no longer appears:

+----+-------------------------------------------+-------+
| id | title                                     | price |
+----+-------------------------------------------+-------+
| 1 | Lord of the Things                         | 8.99  |
| 3 | Parachuting for You and Your Kangaroo      | 19.99 |
+----+-------------------------------------------+-------+

Note 

Be careful when using DELETE because once a row is removed, it's lost forever. Hence, be particularly wary when specifying a nonunique column in the WHERE clause, such as you have here. In your small database, you know that only a single row will be deleted, but in a real-world database, you can easily end up accidentally deleting a whole bunch of records if you use a badly thought-out WHERE clause. You can reduce the chances of this happening by specifying a WHERE clause on a uniquely valued field (such as a primary key).

We've now covered enough of the basics of the SQL syntax to move on and show how you can use it to access databases in a JSP page.


MySQL Home | All MySQL Tutorials | Latest MySQL Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Sathya Narayana
Querying Data with the JSTL in JSP
Deleting Data in MySQL
Modifying data and using WHERE clause in MySQL
Querying the Database in MySQL
Inserting Data into Tables in MySQL
Changing the Structure of an Existing Table in MySQL
The Exception Object in JSP
The Application Object in JSP
The Session Object in JSP
The Out Object in JSP
The Response Object in JSP
The Request Object in JSP
Tag Libraries in JSP
Scriptlets and Expressions in JSP
Declarations in JSP

More Tutorials in MySQL
Windows cannot access the specified device, path or file. You may not have the appropriate permissions to access them.
ERROR 1251: Client does not support authentication protocol requested by server; consider upgrading MySQL client
Changing the Structure of an Existing Table in MySQL
Inserting Data into Tables in MySQL
Querying the Database in MySQL
Modifying data and using WHERE clause in MySQL
Deleting Data in MySQL
What is SQL Injection
MySQL Strengths and Weaknesses
Table __________ is marked as crashed and should be repaired.

More Latest News
Most Viewed Articles (in MySQL )
Changing the Structure of an Existing Table in MySQL
Querying the Database in MySQL
Deleting Data in MySQL
ERROR 1251: Client does not support authentication protocol requested by server; consider upgrading MySQL client
Table __________ is marked as crashed and should be repaired.
What is SQL Injection
MySQL Strengths and Weaknesses
Inserting Data into Tables in MySQL
Modifying data and using WHERE clause in MySQL
Windows cannot access the specified device, path or file. You may not have the appropriate permissions to access them.
Most Emailed Articles (in MySQL)
MySQL Strengths and Weaknesses
Inserting Data into Tables in MySQL
Modifying data and using WHERE clause in MySQL
Deleting Data in MySQL
ERROR 1251: Client does not support authentication protocol requested by server; consider upgrading MySQL client
Windows cannot access the specified device, path or file. You may not have the appropriate permissions to access them.
Table __________ is marked as crashed and should be repaired.
What is SQL Injection
Changing the Structure of an Existing Table in MySQL
Querying the Database in MySQL