T Sql 简明教程
T-SQL - DELETE Statement
SQL Server DELETE 查询用于从表中删除现有记录。
The SQL Server DELETE Query is used to delete the existing records from a table.
您必须将 WHERE 子句与 DELETE 查询一起使用以删除选定的行,否则将删除所有记录。
You have to use WHERE clause with DELETE query to delete selected rows, otherwise all the records would be deleted.
Syntax
以下是有 WHERE 子句的 DELETE 查询的基本语法 −
Following is the basic syntax of DELETE query with WHERE clause −
DELETE FROM table_name
WHERE [condition];
可以使用 AND 或 OR 运算符组合 N 个条件。
You can combine N number of conditions using AND or OR operators.
Example
考虑包含以下记录的 CUSTOMERS 表:
Consider the CUSTOMERS table having the following records −
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 Muffy 24 Indore 10000.00
以下命令是一个示例,它将 DELETE 一个 ID 为 6 的客户 −
Following command is an example, which would DELETE a customer, whose ID is 6 −
DELETE FROM CUSTOMERS
WHERE ID = 6;
CUSTOMERS 表现在将具有以下记录。
CUSTOMERS table will now have the following records.
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 Muffy 24 Indore 10000.00
如果你想从 CUSTOMERS 表中删除所有记录,你不需要使用 WHERE 子句。DELETE 查询将如下所示 −
If you want to DELETE all the records from CUSTOMERS table, you do not need to use WHERE clause. DELETE query would be as follows −
DELETE FROM CUSTOMERS;
CUSTOMERS 表现在没有任何记录。
CUSTOMERS table now will not have any record.