How to Import multiple csv/text files into SQL Server DB
Importing data into SQL Server DB from CSV/Text Files
This Tutorial uses SQL Server 2012 and CSV file that contains data to be
import.
-
Step 1: Create File Paths And Import csv File
- Create folder "C:\ImportingFilesToDb".
- Create Subfolder 1 =>"C:\ImportingFilesToDb\NewFiles" : The csv file will be kept in this location.
- Create Subfolder 2 =>"C:\ImportingFilesToDb\Archive" : The csv file will be archived in this location after being processed.
- Download the CSV File and move it into subfolder 1 -
Step 2: Create SQL Tables and the stored Procedure
- Create Table 1 => price_index : Holds imported csv data.
Download Script Create price_index table
- Create Table 2 => files_logtable: Keepsrecords of processed file names.
Download Script Create files_logtable
- Create Store Procedure; The procedure contains code to read and import data from CSV files into SQL server.
Download Script Create import_files procedure
Execute the Procedure as below.

Exec import_files 'C:\ImportingFilesToDb\NewFiles\', '*.csv', 'price_index'
See final output below.



Good stuff!
ReplyDelete