By: Sathya Narayana in MySQL Tutorials on 2010年10月24日 [フレーム]
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 | +----+-------------------------------------------+-------+
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.
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
Most Viewed Articles (in MySQL )
Use a dynamic table name in a SQL Server SELECT statement
Changing the Structure of an Existing Table in MySQL
Modify a auto_increment id column in mysql to accept a 5 digit random number instead
mysqldumpslow in MySQL - Summarize slow query log.
Finding slow queries in MySQL - Enable slow query log.
Sample my.cnf (my.ini) for MySQL with 1GB RAM
Inserting Data into Tables in MySQL
MySQL Strengths and Weaknesses
Modifying data and using WHERE clause in MySQL
Latest Articles (in MySQL)
Use a dynamic table name in a SQL Server SELECT statement
Finding slow queries in MySQL - Enable slow query log.
mysqldumpslow in MySQL - Summarize slow query log.
Sample my.cnf (my.ini) for MySQL with 1GB RAM
Modify a auto_increment id column in mysql to accept a 5 digit random number instead
Changing the Structure of an Existing Table in MySQL
Inserting Data into Tables in MySQL
Querying the Database in MySQL
Use a dynamic table name in a SQL Server SELECT statement
Finding slow queries in MySQL - Enable slow query log.
mysqldumpslow in MySQL - Summarize slow query log.
Sample my.cnf (my.ini) for MySQL with 1GB RAM
Modify a auto_increment id column in mysql to accept a 5 digit random number instead
Changing the Structure of an Existing Table in MySQL
Inserting Data into Tables in MySQL
Querying the Database in MySQL
© 2023 Java-samples.com
Tutorial Archive: Data Science React Native Android AJAX ASP.net C C++ C# Cocoa Cloud Computing EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Trends WebServices XML Office 365 Hibernate
Latest Tutorials on: Data Science React Native Android AJAX ASP.net C Cocoa C++ C# EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Cloud Computing WebServices XML Office 365 Hibernate