使用 INSERT
语句在已经存在的表中插入数据。
示例如下:
假设有如下所示数据的表 t1 和 t2:
obclient> CREATE TABLE t1(c1 int primary key, c2 int) partition BY key(c1) partitions 4;
Query OK, 0 rows affected (0.16 sec)
obclient> CREATE TABLE t2(c1 int primary key, c2 int);
Query OK, 0 rows affected (0.16 sec)
obclient> SELECT * FROM t2;
+----+------+
| c1 | c2 |
+----+------+
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 4 | 4 |
+----+------+
4 rows in set (0.06 sec)
- 向表 t1 中插入一行数数据。
obclient> INSERT INTO t1 VALUES(1,1);
Query OK, 1 row affected (0.01 sec)
obclient> SELECT * FROM t1;
+----+------+
| c1 | c2 |
+----+------+
| 1 | 1 |
+----+------+
1 row in set (0.04 sec)
- 向表 t1 中插入多行数据。
obclient> INSERT t1 VALUES(1,1),(2,default),(2+2,3*4);
Query OK, 3 rows affected (0.02 sec)
Records: 3 Duplicates: 0 Warnings: 0
obclient> SELECT * FROM t1;
+----+------+
| c1 | c2 |
+----+------+
| 1 | 1 |
| 2 | NULL |
| 4 | 12 |
+----+------+
3 rows in set (0.02 sec)
更多 INSERT
语句相关的语法请参见 INSERT。