Create Table And Put Data In SQL Server Using CSV File

In this article I will show you how you can create a table and import data from a csv file into sql server. In this process first we create a csv file with data and then use that file for creating a table.
 
Points to remember
  • This functionality uses only CSV and TXT files.
  • When creating a CSV file do not leave any blank cells; try to delete them.
Step 1
 
Create your CSV file with data. Your Header name will use a Table Field Name. You can see in the below image I created a file with the following data. 
 
Create Table And Put Data In SQL Server Using CSV File
 
Step 2
 
Open your SQL Server Management Studio. Here SQL Server Management Studio V18.6. 
 
Step 3
 
Create a database if you do not have any.
 
Step 4
 
Right click on your database name then click on Tasks and then click on Import Flat Files.
 
Create Table And Put Data In SQL Server Using CSV File
 
Step 5
 
Now you see a wizard with some information; click on Next button.
 
Create Table And Put Data In SQL Server Using CSV File
 
Step 6
 
In this step you have three fields. Fill these fields and then click on Next button.
  1. Location of your File: Select your CSV file from your computer
  2. New Table Name: Give your new table name which must be different from other existing tables
  3. Schema: Select your schema.
Create Table And Put Data In SQL Server Using CSV File
 
Step 7
 
In the next step you will see a preview of your file data. As you see in the below image we have same preview as our file data. Now click on Next button.
 
Create Table And Put Data In SQL Server Using CSV File
 
Step 8
 
In the next step you see field names which are the headers of your CSV file. If you want to change a field nameyou can change it here. You can also give primary key constraint and null constraint from here. After all changes are made, click on next button.
 
Create Table And Put Data In SQL Server Using CSV File
 
Step 9
 
Now you can see imported details. Verify details and then click on Finish button.
  1. Name: This is owner's name of your computer
  2. Database name: Database name in which you import this file.
  3. Table Name: Your new table name with schema
  4. File to be imported: Your file path
Create Table And Put Data In SQL Server Using CSV File
 
Step 10
 
In this step you see a message that your data is imported. Click on close button and close the wizard.
 
Create Table And Put Data In SQL Server Using CSV File
 
Below is the image of created table design and imported data.
 
Table Design 
 
Create Table And Put Data In SQL Server Using CSV File
 
Table Data
 
Create Table And Put Data In SQL Server Using CSV File
 
I hope this article helped you. If so, please share with your friends. 


Similar Articles