在 SQL 中 快速 批量 插入数据的方法

时间:2022-01-29 00:44:29

方法1:逐条执行,速度慢。

INSERT INTO testimport (name, message)
VALUES ('testname', 'jfksdfkdsfjksadljfkdsfjsdlafjdaslkfjasfd');

INSERT INTO testimport (name, message)
VALUES ('testname', 'jfksdfkdsfjksadljfkdsfjsdlafjdaslkfjasfd');

INSERT INTO testimport (name, message)
VALUES ('testname', 'jfksdfkdsfjksadljfkdsfjsdlafjdaslkfjasfd');

 

方法2:批量执行,适用于 SQL Server。

INSERT INTO testimport (name, message)
VALUES
('testname', 'jfksdfkdsfjksadljfkdsfjsdlafjdaslkfjasfd'),
('testname', 'jfksdfkdsfjksadljfkdsfjsdlafjdaslkfjasfd'),
('testname', 'jfksdfkdsfjksadljfkdsfjsdlafjdaslkfjasfd');

 

方法3:批量执行,适用于Oracle。

INSERT ALL 
    INTO A (name, message) VALUES ('testname', 'jfksdfkdsfjksadljfkdsfjsdlafjdaslkfjasfd')
    INTO A (name, message) VALUES ('testname', 'jfksdfkdsfjksadljfkdsfjsdlafjdaslkfjasfd')
    INTO A (name, message) VALUES ('testname', 'jfksdfkdsfjksadljfkdsfjsdlafjdaslkfjasfd')
SELECT 1
FROM DUAL;

 

参考资料

https://blog.csdn.net/fukaiit/article/details/80691665