Transfer of Data from CSV file to Sql Server table. The CSV stands for Comma Separated value, Basically the CSV file would be the text file. The values which are separated by comma are stored in this file. The Values form CSV file can be transferred to the SQL server table. Example : Create one table for testing.
Create Table Teams (id bigint, name varchar(100), NoofMatches numeric(10,0), TotalPoints Numeric(10,0)
Now the table named Teams are created. Create the CSV file with the values. Consider the CSV file name was “Teams.TXT”. 1,India,150,250 2,Australia,170,300 3,England,124,200 The above values are in the text file. Here is the script with get the values form the text file and insert into the sql table.
BULK INSERT Teams --- This is the Table name which you needs to insert value FROM ‘c:\Teams.txt’ ---- This is the TXT file name which has the CSV values. WITH ( FIELDTERMINATOR = ‘,’, ---- This is for specify the separator value. The values are separated by the above mentioned value. The field values should be separated by the value “,”. ROWTERMINATOR = ‘\n’ ----- This is for specify the Row end separator. By default “\n” is the row terminator. ) GO
After run the above code the values which available in the csv file would be transferred to the table “Teams”. The bulk insert is the statement which gets the values from the CSV files. For confirm the data transfer check with select Query.
Select * from Teams
|
No responses found. Be the first to respond and make money from revenue sharing program.
|