Created
June 28, 2021 01:43
-
-
Save brain90/a507dba71345b9a99f3596ab599cb698 to your computer and use it in GitHub Desktop.
Fastest way to load data into sql server
This file contains hidden or 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
--- 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