Passing a CSV file (separate files through a delimiter, such as a tab) to an SQL table is a frequently required process. There are several ways, importing and exporting the data to the travel assistant of a tool Built-in SQL Server.
1. First we create a CSV file, demolished by commas:
1,white,854587
2,black,784454
3,blue,852456
And we save the file: C:\file.txt
Sql Server Bulk Insert Example
Another way to solve it is through a bulk insert, here is a way simple to do:1. First we create a CSV file, demolished by commas:
1,white,854587
2,black,784454
3,blue,852456
Post Popular
2. Then we create the table where the data will be stored:
CREATE TABLE Dbo.CSVToTabla
(
ID INT,
Colors VARCHAR(20),
Code int
) GO
3. Now we execute the bulk insert, passing the path where the CSV file is located and the delimiter is parameterized, for this case the comma:(
ID INT,
Colors VARCHAR(20),
Code int
) GO
--BULK INSERT
BULK
INSERT Dbo.CSVToTabla
FROM 'c:\file.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO
4. Finally we consult the data:BULK
INSERT Dbo.CSVToTabla
FROM 'c:\file.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO