CSV stands for comma-separated values, sometimes referred to as comma-separated values. and
If the TXT file is loaded, then the file should have a comma-separated value. And the file should be like this
Here is the script to create the table:
CREATE TABLE Employee (
Id int,
Name VARCHAR (100),
Designation VARCHAR (100)
)
I created the location "f a txt and CSV file: \ \ mypublis \ \ 's TXT file name is TestToInsert.txt
Now run the following script to load all the data from the TXT file into the database table. If any errors in any row are not inserted, the other rows are inserted.
I create an ID column in the emloyee table integer, if any row in my file has a string of data, the first part of it refers to going to the ID column so that the row is not inserted and will be continew with the next line.
BULK
INSERT Employee
From ' f:\\mypublis\\testtoinsert.txt '--location with filename
With
(
FieldTerminator = ', ',
Rowterminator = ' \ n '
)
GO
Now see the Data sheet –:
Execute the same script for the CSV file.
With CSV file –:
Siv_csv, CEO
One by one, Brijendra_csv, Operatore
Micro, Company
BULK
INSERT Employee
From ' f:\\mypublis\\csvtest.csv '--location with filename
With
(
FieldTerminator = ', ',
Rowterminator = ' \ n '
)
GO
SELECT *from Employee
The output will be –:
BULK insert to import a CSV or TXT file into SQL Server