Importing a CSV file into SQL Server database table is very easy. It can be done using SQL Server Management Studio.
As you can see, here we have one CSV file named as Data.CSV.
This file is located in local folder Inputfile.
Now, we will import this file data into SQL Server data base(version 2019) table.
The steps to load data from a csv file into a SQL Server table are as follows.
Right click on database where you want to load file data then click on Tasks context menu.
Next, click on Import Flat File ( This option is for .CSV ,or .txt format files).
After that you will see an Introduction pop window opens.
Click on, Specify input file and the choose file that you want to load in table.
Specify table name that is InputDatFile then choose schema that is dbo.
This table will be used to load input file data. After that click on Next button.
Now Preview Data window opens, here you can see the preview of your data.
You can validate the data. If everything is correct then click on Next button.
Once you click on Next button, a Modify columns window open.
Here you can make changes in column data type, set primary key columns so on.. as per your requirement. Once you done with that, click on Next button.
[Also Read: SQL Server Bulk Insert(BCP)]
After that, it displays you Summary of you inputs like input file names, database name and table name just to validate that you have chosen right file or not.
After that just click on Finish button to complete final step.
Once you click on Finish button, it starts loading file data into table. When loading is completed, you will get a Success message in dialog box.
Now you can check whether the records are inserted in table or not.
SELECT * FROM InputDataFile
As you can see, now you have imported CSV file data into SQL table, and table having same records as it were there in input file.
Also Read..
Copy or Delete files from directory in SQL Server