• INSERT
    • 语法图
    • 示例
    • MySQL 兼容性
    • 另请参阅

    INSERT

    使用 INSERT 语句在表中插入新行。

    语法图

    InsertIntoStmt:

    InsertIntoStmt

    PriorityOpt:

    PriorityOpt

    IgnoreOptional:

    IgnoreOptional

    IntoOpt:

    IntoOpt

    TableName:

    TableName

    InsertValues:

    InsertValues

    示例

    1. mysql> CREATE TABLE t1 (a int);
    2. Query OK, 0 rows affected (0.11 sec)
    3. mysql> CREATE TABLE t2 LIKE t1;
    4. Query OK, 0 rows affected (0.11 sec)
    5. mysql> INSERT INTO t1 VALUES (1);
    6. Query OK, 1 row affected (0.02 sec)
    7. mysql> INSERT INTO t1 (a) VALUES (1);
    8. Query OK, 1 row affected (0.01 sec)
    9. mysql> INSERT INTO t2 SELECT * FROM t1;
    10. Query OK, 2 rows affected (0.01 sec)
    11. Records: 2 Duplicates: 0 Warnings: 0
    12. mysql> SELECT * FROM t1;
    13. +------+
    14. | a |
    15. +------+
    16. | 1 |
    17. | 1 |
    18. +------+
    19. 2 rows in set (0.00 sec)
    20. mysql> SELECT * FROM t2;
    21. +------+
    22. | a |
    23. +------+
    24. | 1 |
    25. | 1 |
    26. +------+
    27. 2 rows in set (0.00 sec)
    28. mysql> INSERT INTO t2 VALUES (2),(3),(4);
    29. Query OK, 3 rows affected (0.02 sec)
    30. Records: 3 Duplicates: 0 Warnings: 0
    31. mysql> SELECT * FROM t2;
    32. +------+
    33. | a |
    34. +------+
    35. | 1 |
    36. | 1 |
    37. | 2 |
    38. | 3 |
    39. | 4 |
    40. +------+
    41. 5 rows in set (0.00 sec)

    MySQL 兼容性

    INSERT 语句与 MySQL 完全兼容。如有任何兼容性差异,请在 GitHub 上提交 issue。

    另请参阅

    • DELETE
    • SELECT
    • UPDATE
    • REPLACE