DELETE

DELETE 语句用于从指定的表中删除行。

语法图

DeleteFromStmt

DELETE - 图1

  1. DeleteFromStmt ::=
  2. 'DELETE' TableOptimizerHints PriorityOpt QuickOptional IgnoreOptional ( 'FROM' ( TableName TableAsNameOpt IndexHintListOpt WhereClauseOptional OrderByOptional LimitClause | TableAliasRefList 'USING' TableRefs WhereClauseOptional ) | TableAliasRefList 'FROM' TableRefs WhereClauseOptional )

示例

  1. CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, c1 INT NOT NULL);
  1. Query OK, 0 rows affected (0.11 sec)
  1. INSERT INTO t1 (c1) VALUES (1),(2),(3),(4),(5);
  1. Query OK, 5 rows affected (0.03 sec)
  2. Records: 5 Duplicates: 0 Warnings: 0
  1. SELECT * FROM t1;
  1. +----+----+
  2. | id | c1 |
  3. +----+----+
  4. | 1 | 1 |
  5. | 2 | 2 |
  6. | 3 | 3 |
  7. | 4 | 4 |
  8. | 5 | 5 |
  9. +----+----+
  10. 5 rows in set (0.00 sec)
  1. DELETE FROM t1 WHERE id = 4;
  1. Query OK, 1 row affected (0.02 sec)
  1. SELECT * FROM t1;
  1. +----+----+
  2. | id | c1 |
  3. +----+----+
  4. | 1 | 1 |
  5. | 2 | 2 |
  6. | 3 | 3 |
  7. | 5 | 5 |
  8. +----+----+
  9. 4 rows in set (0.00 sec)

MySQL 兼容性

DELETE 语句与 MySQL 完全兼容。如发现任何兼容性差异,请尝试 TiDB 支持资源

另请参阅