SQL Server – Import CSV file to SQL table – Bulk-Insert
Here is an example – Import CSV file to SQL table using Bulk-Insert
CSV file means Comma Separated Values file.
USE testdb GO CREATE TABLE table1 ( id INT, name VARCHAR(255), address VARCHAR(255) ) GO
Create CSV file in Shared folder on any remote location with name csv.txt
Suppose location of the file is \\dcc-566\Share\CSV.txt
Content of CSV file as :
Now let‘s Import this CSV file into Table1.
BULK INSERT table1 FROM '\\dcc-566\Share\CSV.txt' WITH ( FIELDTERMINATOR = ',', ROWTERMINATOR = '\n' ) GO
Pingback: SQL Server – Comma Separated Values | Varinder Sandhu
but if your remote machine has a password, this method will fail.
You should have the access of the path/location that you mentioned in the script.
It fails only when u cannot access the path/location that you mentioned in the script.
Before running the script you should check you have access of that path/location or not.
You can simply put your path/location in the RUN then press enter.
If you have any other doubt or query. Please let me know.
I want to read multiple CSV files and not only one file, do you have the query for that?
Hi Ayabuya,
Refer this : http://www.databasejournal.com/features/mssql/article.php/3325701/Import-multiple-Files-to-SQL-Server-using-T-SQL.htm