SQL Server - How do I import and Export CSV File into SQL Server

in Education2 years ago

Learn How to import and Export CSV file into SQL Server. Previously i posted about multiple tutorials on how to install SQL server on Windows. I also posted about the CRUD operations in SQL Server. Now I want to cover how one can import the data into the SQL Server.

Here the data happens to be CSV. The CSV file is basically Comma separated value file which contains the data specific to the typical data that you can manipulate into the excel spreadsheet. Considering the data that we happen to manipulate is going to be the tabular data.

So the goal of this tutorial is basically two things - First being able to import the data into the table in the SQL Server and Second being able to export the data outside the SQL Server table. This way things would be easier to manipulate add into the SQL Server and take out as required.

If you are interested in checking out the Video instructions, you should check out the video.

Your first step here is that you need the following things:

  1. SQL Server Management Studio
  2. SQL Server 2019 Developer Edition
  3. CSV File data

Once you have these three things the above video has the step by step instructions for you to import the data as a table into the SQL Server database. And the export for the same data can be done as well. I have covered that in the video too. So you may want to watch that till the end of the video.

You can import the data through multiple steps like by using the query and also using the wizard. Now the wizard method is lot easier and also good for validating and verifying the data being transferred. I'd recommend you to try that if you have plans to do this with your clients data.

Things to note in this case of the Import and Export.

  • Say if you have a large data over 1GB or more you may experience data corruption and other data specific issues that could affect the Wizard.
  • You may also have some other errors based on the original data file condition. If the file is corrupt that would also affect the import and export state there.
  • Most of the errors specific to the SQL server issues are visible with the SQL Server management Studio and you can then google based on the Error Code.
  • You are not limited to SSMS tool from Microsoft, you can use Azure data studio and other external data tools for performing this operation.
  • Some TSV files and also the data files with the tabular data can be imported the same way.

SQL Server data tools make use of the SQL Server integration service to perform the copy and paste operation for the data transfer and also does the tabular data design internally. Which you can view in the wizard. Some of the time that would be easier to view and learn from as you do this multiple times.

Do note that SQL Server 2022 or maybe next year new version of SQL server may launch and so the tutorial may change a bit in terms of the instructions. So on that note we have to check out on how that would work around. A lot of interesting things may need to be watched out on that front.

If you happen to like this content, do give me feedback over there and that would help me improve my efforts in near future.

Sort:  

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support.