使用 INSERT 语句在已经存在的表中插入数据。

    示例如下:

    假设有如下所示数据的表 t1 和 t2:

    1. obclient> CREATE TABLE t1(c1 int primary key, c2 int) partition BY key(c1) partitions 4;
    2. Query OK, 0 rows affected (0.16 sec)
    3. obclient> CREATE TABLE t2(c1 int primary key, c2 int);
    4. Query OK, 0 rows affected (0.16 sec)
    5. obclient> SELECT * FROM t2;
    6. +----+------+
    7. | c1 | c2 |
    8. +----+------+
    9. | 1 | 1 |
    10. | 2 | 2 |
    11. | 3 | 3 |
    12. | 4 | 4 |
    13. +----+------+
    14. 4 rows in set (0.06 sec)
    • 向表 t1 中插入一行数数据。
    1. obclient> INSERT INTO t1 VALUES(1,1);
    2. Query OK, 1 row affected (0.01 sec)
    3. obclient> SELECT * FROM t1;
    4. +----+------+
    5. | c1 | c2 |
    6. +----+------+
    7. | 1 | 1 |
    8. +----+------+
    9. 1 row in set (0.04 sec)
    • 向表 t1 中插入多行数据。
    1. obclient> INSERT t1 VALUES(1,1),(2,default),(2+2,3*4);
    2. Query OK, 3 rows affected (0.02 sec)
    3. Records: 3 Duplicates: 0 Warnings: 0
    4. obclient> SELECT * FROM t1;
    5. +----+------+
    6. | c1 | c2 |
    7. +----+------+
    8. | 1 | 1 |
    9. | 2 | NULL |
    10. | 4 | 12 |
    11. +----+------+
    12. 3 rows in set (0.02 sec)

    更多 INSERT 语句相关的语法请参见 INSERT