Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

mssql how to insert more than 1000 rows

BEGIN TRANSACTION; -- Whenever possible use transactions when dealing with large amounts of data
INSERT INTO [database].[dbo].[table_name] ([field1], [field2], [field3])
SELECT 'value for row 1 field 1', 'value for row 1 field 2', 'value for row 1 field 3' UNION ALL
SELECT 'value for row 2 field 1', 'value for row 2 field 2', 'value for row 2 field 3' UNION ALL
-- ...N-thousand other rows...
SELECT 'value for row n-1 field 1', 'value for row n-1 field 2', 'value for row n-1 field 3' UNION ALL
SELECT 'value for row n field 1', 'value for row n field 2', 'value for row n field 3'; -- No 'UNION ALL' statement on the last line
COMMIT TRANSACTION;
 
PREVIOUS NEXT
Tagged: #mssql #insert #rows
ADD COMMENT
Topic
Name
5+4 =