The statement to delete table records in MySQL is DELETE, and the syntax is DELETE FROM table_name WHERE condition, which is used to specify deletion conditions. Use caution when using the DELETE statement as it permanently deletes records. Additionally, there are other syntax variations including using LIMIT to limit the number of records deleted, using ORDER BY to sort to delete records, and using TRUNCATE to quickly delete all records.
MySQL statement to delete table records
The statement to delete table records in MySQL is DELETE. Its basic syntax is as follows:
<code>DELETE FROM table_name WHERE condition;</code>
Where:
table_name
is the name of the table from which records are to be deleted. condition
is an optional condition that specifies which records to delete. Usage Example
For example, to delete all users with user_type = 'guest'
from the users
table For records, you can use the following statement:
<code>DELETE FROM users WHERE user_type = 'guest';</code>
Note
statement will permanently delete the record, so please use it Be careful.
clause is not specified, all records in the table will be deleted. The
statement does not automatically commit changes. Changes need to be manually committed or rolled back using
COMMIT or
ROLLBACK.
Other syntax variations
In addition to the basic syntax, theDELETE statement has other syntax variations, including:
to limit the number of deleted records:
<code>DELETE FROM table_name WHERE condition LIMIT number_of_rows;</code>
Sort the records to be deleted:
<code>DELETE FROM table_name WHERE condition ORDER BY column_name DESC LIMIT number_of_rows;</code>
to quickly delete all records:
<code>TRUNCATE TABLE table_name;</code>
TRUNCATE is more efficient than
DELETE because it does not perform line-by-line deletion. However, it cannot recover deleted records.
The above is the detailed content of Statement to delete table records in mysql. For more information, please follow other related articles on the PHP Chinese website!