4.2.16. MySQL DELETE statement

发布时间 :2025-10-25 12:31:19 UTC      

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

You can do it in the mysql> Execute the command at a command prompt or in a 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 instance will be deleted runoob_tbl In the table runoob_id A record of 3:

DELETE statement:

mysql>useRUNOOB;Databasechangedmysql>DELETEFROMrunoob_tblWHERErunoob_id=3;QueryOK,1rowaffected(0.23sec)

Use PHP scripts to delete data

PHP usage mysqli_query() Function to execute the SQL statement, you can use it in the SQL DELETE command or not WHERE Clause.

This function is similar to the mysql> The command executes the SQL command with the same effect.

Example

The following PHP instances will be deleted runoob_tbl In the table runoob_id A record of 3:

MySQL DELETE clause test:

<?php$dbhost='localhost';//mysql服务器主机地址$dbuser='root';//mysql用户名$dbpass='123456';//mysql用户名密码$conn=mysqli_connect($dbhost,$dbuser,$dbpass);if(!$conn){die('连接失败:'.mysqli_error($conn));}//设置编码,防止中文乱码mysqli_query($conn,"set
names utf8");$sql='DELETE FROM runoob_tbl WHERE
runoob_id=3';mysqli_select_db($conn,'RUNOOB');$retval=mysqli_query($conn,$sql);if(!$retval){die('无法删除数据:'.mysqli_error($conn));}echo'数据删除成功!';mysqli_close($conn);?>

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.