Last active
February 4, 2022 15:57
-
-
Save dami-i/c421fca29885a3560f0f36a2fcd0aa43 to your computer and use it in GitHub Desktop.
Insert more than 1000 rows on one transaction only (SQL Server - T-SQL)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment