SQL DELETE查询用于从表中删除现有记录,您可以将WHERE子句与DELETE查询一起使用,以删除所选的行,否则将删除所有记录。
Delete Query - 语法
带WHERE子句的DELETE查询的基本语法如下-
DELETE FROM table_name WHERE [condition];
您可以使用AND或OR运算符组合N个条件。
Delete Query - 示例
考虑具有以下记录的CUSTOMERS表-
+----+----------+-----+-----------+----------+ | ID | NAME | AGE | ADDRESS | SALARY | +----+----------+-----+-----------+----------+ | 1 | Ramesh | 32 | Ahmedabad | 2000.00 | | 2 | Khilan | 25 | Delhi | 1500.00 | | 3 | kaushik | 23 | Kota | 2000.00 | | 4 | Chaitali | 25 | Mumbai | 6500.00 | | 5 | Hardik | 27 | Bhopal | 8500.00 | | 6 | Komal | 22 | MP | 4500.00 | | 7 | Learnfk | 24 | Indore | 10000.00 | +----+----------+-----+-----------+----------+
以下代码具有一个查询,该查询将删除ID为6的客户。
SQL> DELETE FROM CUSTOMERS WHERE ID=6;
现在,CUSTOMERS表将具有以下记录。
+----+----------+-----+-----------+----------+ | ID | NAME | AGE | ADDRESS | SALARY | +----+----------+-----+-----------+----------+ | 1 | Ramesh | 32 | Ahmedabad | 2000.00 | | 2 | Khilan | 25 | Delhi | 1500.00 | | 3 | kaushik | 23 | Kota | 2000.00 | | 4 | Chaitali | 25 | Mumbai | 6500.00 | | 5 | Hardik | 27 | Bhopal | 8500.00 | | 7 | Learnfk | 24 | Indore | 10000.00 | +----+----------+-----+-----------+----------+
如果要删除CUSTOMERS表中的所有记录,则无需使用WHERE子句,DELETE查询将如下所示-
SQL> DELETE FROM CUSTOMERS;
现在,CUSTOMERS表将没有任何记录。
参考链接
https://www.learnfk.com/sql/sql-delete-query.html
标签:+----+----------+-----+-----------+----------+,25,CUSTOMERS,无涯,查询,SQL,DELETE,WHE From: https://blog.51cto.com/u_14033984/9257074