Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

MySQL DELETE statement

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

MySQL DELETE statement

You can use SQL's DELETE FROM command to delete records in the MySQL datasheet.

You can execute this command at the mysql > command prompt or in the PHP script.

Grammar

The following is the general syntax for the SQL DELETE statement to delete data from the MySQL data table:

DELETE FROM table_name [WHERE Clause]

If no WHERE clause is specified, all records in the MySQL table are deleted.

You can specify any condition in the WHERE clause

You can delete records in a single table at once.

The WHERE clause is very useful when you want to delete a specified record in a data table.

Delete data from the command line

Here we will use the WHERE clause in the SQL DELETE command to delete the data selected by the MySQL data table runoob_tbl.

Example

The following example deletes a record with a runoob_id of 3 in the runoob_tbl table:

SQL UPDATE statement:

Mysql > use RUNOOB;Database changedmysql > DELETE FROM runoob_tbl WHERE runoob_id=3;Query OK, 1 row affected (0.23 sec)

Use PHP scripts to delete data

PHP uses the mysqli_query () function to execute the SQL statement, and you can use the WHERE clause with or without the SQL DELETE command.

This function has the same effect as the mysql > command that executes the SQL command.

Example

The following PHP instance deletes the record with runoob_id 3 in the runoob_tbl table:

MySQL DELETE clause test:

MySQL UPDATE query

MySQL LIKE clause

Note list

The delete statement is used to delete data from a table. The basic usage is as follows:

Delete from table name where delete condition

The following is an example in the table students:

Delete the line with id 3: delete from students where id=3

Delete all data under the age of 21: delete from students where age

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report