MySQL:插入多行数据


#MySQL 笔记


示例

创建表:

CREATE TABLE test_table (
    c1 varchar(100) not null,
    c2 varchar(100)
) ENGINE = InnoDB CHARACTER SET = utf8mb4;

插入多行:

insert into test_table(c1, c2) values('你好', '中国'), ('你好', '北京');

注意,这里有一个坑:

insert into test_table(c1, c2) values(null, '中国'); -- 报错 (1048, u"Column 'c1' cannot be null")
insert into test_table(c1, c2) values(null, '中国'), ('你好', '上海'); -- 成功,第一条数据的c1列的值变成了默认的空字符串


( 本文完 )