And recently, I have to deal with import a huge load of data (around 200 MB for 1 CSV input file) from CSV files into MS SQL SERVER. So what I had done to achieve this is by using BULK INSERT.
Firstly, prepare a CSV data file with the following content and save as test.csv.
July,Singapore,25
James,Australia,50
May,China,29
And then run scripts as following to load all the data from the CSV file into database.
--Temp table to store the data
CREATE TABLE CSVTest
(
Name VARCHAR(500),
Country VARCHAR(500),
Age INT
)
GO
--Bulk insert into CSVTest
BULK INSERT CSVTest
FROM 'C:\test.csv'
WITH
(
FIELDTERMINATOR=',',
ROWTERMINATOR = '\n'
)
GO
--Get all data from CSVTest
SELECT *
FROM CSVTest
GO
--Drop the temp table
DROP TABLE CSVTest
GO
3 comments:
I am getting a following error.
"Operating system error code 53(The network path was not found )"
Hi, are you trying to import a file that is located on a remote computer?
If so, please make sure that the file is placed in a network share that can be accessed through the computer that running SQL Server.
Good brief and this mail helped me alot in my college assignement. Gratefulness you as your information.
Post a Comment