You can execute the INSERT statements to insert data into tables.
Syntax
the primary key.INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
[INTO] [schema_name.]tbl_name
[(col_name [, col_name] ...)]
{VALUES | VALUE} (value_list) [, (value_list)]
[ON DUPLICATE KEY UPDATE assignment_list]
INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
[INTO] [schema_name.]tbl_name
SET assignment_list
[ON DUPLICATE KEY UPDATE assignment_list]
INSERT [LOW_PRIORITY | HIGH_PRIORITY] [IGNORE]
[INTO] [schema_name.]tbl_name
[(col_name [, col_name] ...)]
SELECT ...
[ON DUPLICATE KEY UPDATE assignment_list]
value_list:
value [, value] ...
value:
{expr | DEFAULT}
assignment_list:
assignment [, assignment] ...
assignment:
col_name = value
Limits on syntax
The following INSERT statements are not supported:
- INSERT IGNORE ON DUPLICATE KEY UPDATE.
INSERT IGNORE INTO tb (id) VALUES(7) ON DUPLICATE KEY UPDATE id = id + 1;
- INSERT statements that contain PARTITION functions.
INSERT INTO tb PARTITION (p0) (id) VALUES(7);
- INSERT statements where the NEXTVAL functions are nested.
INSERT INTO tb(id) VALUES(SEQ1.NEXTVAL + 1);
- INSERT statements that contain column names.
INSERT INTO tb(id1, id2) VALUES(1, id1 + 1);
Limits on distributed transactions
Note If a transaction is processed in the same database shard even when you use table shards,
this transaction is considered as a single-database transaction. For example, a transaction
contains the shard key and the INSERT or UPDATE statement in the transaction is executed
in the same database shard. In this case, this transaction is a single-database transaction.
If the distributed transaction feature is enabled, the INSERT statements that meet the following conditions are not supported:
- No primary key is specified for the table to which data is to be inserted. The following
statements are used as examples:
CREATE TABLE tb(id INT, name VARCHAR(10)); INSERT INTO tb VALUES(1, 'a');
- The table to which data is to be inserted is not sharded. The primary key values are
auto-incremented, but no Distributed Relational Database Service (DRDS) sequence is
used for the primary key. For more information about DRDS sequences. The following
statements are used as examples:
CREATE TABLE tb(id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(10)); INSERT INTO tb(name) VALUES('a'); # The statements are not supported.
You can specify a DRDS sequence for the primary key to enable the preceding statements to be supported. For more information about DRDS sequences. The following statements are used as examples:
CREATE TABLE tb(id INT PRIMARY KEY AUTO_INCREMENT BY GROUP, name VARCHAR(10)); INSERT INTO tb(name) VALUES('a'); # The statements are supported.
References
INSERT Statement for the native MySQL.