Skip to content

Instantly share code, notes, and snippets.

@brain90
Created June 28, 2021 01:43
Show Gist options
  • Save brain90/a507dba71345b9a99f3596ab599cb698 to your computer and use it in GitHub Desktop.
Save brain90/a507dba71345b9a99f3596ab599cb698 to your computer and use it in GitHub Desktop.
Fastest way to load data into sql server
--- Load from table dump_1.csv to dump_100.csv
--- *.csv has million records
DECLARE @i int = 0
DECLARE @fromTable VARCHAR(MAX)
declare @sql varchar(max)
WHILE @i < 100
BEGIN
print @i
set @fromTable = '''D:\mariadb\data\final\dump_'+ cast(@i as varchar(3)) +'.csv'''
set @sql = 'BULK INSERT tblevent
FROM ' + @fromTable + '
WITH
(
FIRSTROW = 1, FIELDTERMINATOR = '';'', ROWTERMINATOR = ''0x0a'',ERRORFILE = ''D:\mariadb\data\final\err.csv'',TABLOCK
)'
SET @i = @i + 1
exec(@sql)
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment