Bulk insert from File SQL Server

For CSVs

bulk insert
ycsoftware.dbo.ycsoftware 
from '\\192.168.1.1\c$\ycsoftware\files\data.txt'
WITH 
(
FIRSTROW = 2,
FIELDTERMINATOR = '\t',  
ROWTERMINATOR = '\n', 
TABLOCK
)

For TSVs

bulk insert
ycsoftware.dbo.ycsoftware 
from '\\192.168.1.1\c$\ycsoftware\files\data.txt'
WITH 
(
FIRSTROW = 2,
FIELDTERMINATOR = ',',  
ROWTERMINATOR = '\n', 
TABLOCK
)

Issues:
Skipping Auto-increment Column
It is highly suggested that you bulk insert into a temporary table first before you move the data into a production table.
IF the query is run outside the server via SQL Management Studio as an example then you use UNC path for the file name.
Bulk insert runs on the server.

Reference:
https://docs.microsoft.com/en-us/sql/t-sql/statements/bulk-insert-transact-sql

Let's share thisShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

Leave a Reply


*