DELETE 语句用于删除表中的现有记录。
DELETE FROM table_name WHERE condition
以下是“Northwind”数据库的“Customers”表中的示例:
CustomerID | CustomerName | ContactName | Address | City | PostalCode | Country |
---|---|---|---|---|---|---|
1 | Alfreds Futterkiste | Maria Anders | Obere Str. 57 | Berlin | 12209 | Germany |
2 | Ana Trujillo Emparedados y helados | Ana Trujillo | Avda. de la Constitución 2222 | México D.F. | 5021 | Mexico |
3 | Antonio Moreno Taquería | Antonio Moreno | Mataderos 2312 | México D.F. | 5023 | Mexico |
4 | Around the Horn | Thomas Hardy | 120 Hanover Sq. | London | WA1 1DP | UK |
5 | Berglunds snabbköp | Christina Berglund | Berguvsvägen 8 | Luleå | S-958 22 | Sweden |
以下 SQL 语句从“Customers”表中删除客户“Alfreds Futterkiste”:
DELETE FROM Customers
WHERE CustomerName = 'Alfreds Futterkiste'
“客户”表现在如下所示:
CustomerID | CustomerName | ContactName | Address | City | PostalCode | Country |
---|---|---|---|---|---|---|
2 | Ana Trujillo Emparedados y helados | Ana Trujillo | Avda. de la Constitucion 2222 | Mexico D.F. | 05021 | Mexico |
3 | Antonio Moreno Taqueria | Antonio Moreno | Mataderos 2312 | Mexico D.F. | 05023 | Mexico |
4 | Around the Horn | Thomas Hardy | 120 Hanover Sq. | London | WA1 1DP | UK |
5 | Berglunds snabbkop | Christina Berglund | Berguvsvagen 8 | Lulea | S-958 22 | Sweden |
您可以删除表中的所有行而不删除表。这意味着表结构、属性和索引将保持不变:
DELETE FROM table_name
以下 SQL 语句删除 Customers 表中的所有行,而不删除表本身:
DELETE FROM Customers