DELETE

The DELETE statement removes rows from a specified table.

Synopsis

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 )

Examples

  1. mysql> CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, c1 INT NOT NULL);
  2. Query OK, 0 rows affected (0.11 sec)
  3. mysql> INSERT INTO t1 (c1) VALUES (1),(2),(3),(4),(5);
  4. Query OK, 5 rows affected (0.03 sec)
  5. Records: 5 Duplicates: 0 Warnings: 0
  6. mysql> SELECT * FROM t1;
  7. +----+----+
  8. | id | c1 |
  9. +----+----+
  10. | 1 | 1 |
  11. | 2 | 2 |
  12. | 3 | 3 |
  13. | 4 | 4 |
  14. | 5 | 5 |
  15. +----+----+
  16. 5 rows in set (0.00 sec)
  17. mysql> DELETE FROM t1 WHERE id = 4;
  18. Query OK, 1 row affected (0.02 sec)
  19. mysql> SELECT * FROM t1;
  20. +----+----+
  21. | id | c1 |
  22. +----+----+
  23. | 1 | 1 |
  24. | 2 | 2 |
  25. | 3 | 3 |
  26. | 5 | 5 |
  27. +----+----+
  28. 4 rows in set (0.00 sec)

MySQL compatibility

The DELETE statement in TiDB is fully compatible with MySQL. If you find any compatibility differences, report a bug.

See also