Home > Database > Mysql Tutorial > body text

What is the use of the database delete statement delete?

青灯夜游
Release: 2020-10-23 14:50:04
Original
25836 people have browsed it

The database delete statement delete is used to delete one or more rows of data in a table. The syntax format is "DELETE FROM

[WHERE clause] [ORDER BY clause] [LIMIT clause]"; When you do not use the WHERE clause to define the deletion conditions for the deletion operation, all data will be deleted.

What is the use of the database delete statement delete?

(Recommended tutorial: mysql video tutorial)

Delete statement delete

The DELETE statement can delete one or more rows of data in the table.

The syntax format is:

DELETE FROM <表名> [WHERE 子句] [ORDER BY 子句] [LIMIT 子句]
Copy after login

The syntax description is as follows:

: Specify the name of the table to delete data.

  • ORDER BY clause: Optional. Indicates that when deleting, rows in the table will be deleted in the order specified in the clause.

  • WHERE clause: Optional. Indicates that the deletion conditions are limited for the deletion operation. If this clause is omitted, it means deleting all rows in the table.

  • LIMIT clause: Optional. Used to tell the server the maximum number of rows to be deleted before the control command is returned to the client.

  • Example 1: Delete all data in the table

    Delete all data in the tb_courses table

    mysql> DELETE FROM tb_students;
    Query OK, 3 rows affected (0.12 sec)
    mysql> SELECT * FROM tb_students;
    Empty set (0.00 sec)
    Copy after login

    Example 2: Delete data in the table based on conditions

    In the tb_students table, delete the record with id 4

    mysql> DELETE FROM tb_students
        -> WHERE id=4;
    Query OK, 1 row affected (0.00 sec)
    mysql> SELECT * FROM tb_students;
    +----+-------+---------+------+------+--------+------------+
    | id | name  | dept_id | age  | sex  | height | login_date |
    +----+-------+---------+------+------+--------+------------+
    |  1 | Dany  |       1 |   25 | F    |    160 | 2015-09-10 |
    |  2 | Green |       3 |   23 | F    |    158 | 2016-10-22 |
    |  3 | Henry |       2 |   23 | M    |    185 | 2015-05-31 |
    |  5 | Jim   |       1 |   24 | M    |    175 | 2016-01-15 |
    |  6 | John  |       2 |   21 | M    |    172 | 2015-11-11 |
    |  7 | Lily  |       6 |   22 | F    |    165 | 2016-02-26 |
    |  8 | Susan |       4 |   23 | F    |    170 | 2015-10-01 |
    +----+-------+---------+------+------+--------+------------+
    4 rows in set (0.00 sec)
    Copy after login

    It can be seen from the running results that the record with id 4 has been been deleted.

    The above is the detailed content of What is the use of the database delete statement delete?. For more information, please follow other related articles on the PHP Chinese website!

    Related labels:
    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template