Skip to main content

Command Palette

Search for a command to run...

SQL : Insert a large number of records using SQL

Published
1 min read
SQL : Insert a large number of records using SQL
S

I love learning about technology and sharing that with others

Learning

Use the below mentioned query to insert multiple records this is the fastest way available.

-- don't add "UNION ALL" statement on the last line
INSERT INTO mytable(companyid, category, sub, catalogueref)
SELECT '10197', 'cat', 'sub', '123' UNION ALL
SELECT '10197', 'cat2', 'sub2', '124' UNION ALL
-- ... other N-thousand rows
SELECT '10197', 'catN-1', 'subN-1', '12312' UNION ALL
SELECT '10197', 'catN', 'subN', '12313';
23 views

More from this blog

H

hashcodehub

271 posts

Consistent, Passionate and Organized :)