尹良灿得闲

巴甫洛夫很忙……巴甫洛夫正在死亡

SQL:一次性插入多个元组

| Comments

书本上没有,在 StackOverflow 找到了,做一下笔记

句式一:

1
2
3
4
5
INSERT INTO 'tablename' ('column1', 'column2') VALUES
('data1', 'data2'),
('data3', 'data4'),
('data5', 'data6'),
('data7', 'data8')


句式二:

1
2
3
4
5
INSERT INTO 'tablename'
      SELECT 'data1' AS 'column1', 'data2' AS 'column2'
UNION SELECT 'data3', 'data4'
UNION SELECT 'data5', 'data6'
UNION SELECT 'data7', 'data8'

参考资料

Comments