How to Import Delimited Text Files into a SQL Server 2005 database
Use the SQL Server Import and Export Wizard to import delimited text files.
by
Doug
Updated May 16, 2010
Choose a Flat File Data Source to import into SQL Server 2005, and change the Format settings to correspond with your text file.
Use the Advanced page to add a new column and configure its properties.
Choose the Destination Table to use for importing data into.
Edit the Column Mappings.
This step-by-step goes through the process of importing delimited text files into a SQL Server 2005 database. The text files that I used while writing this article were the recently released tab delimited AOL search data (See: How to Import Delimited Text Files into Microsoft Excel). The following example should help you better understand how to import different types of flat files into SQL Server 2005.
- Open Microsoft SQL Server Management Studio.
- Click the plus sign next to the Databases folder in the Object Explorer window and find the database you want to use to Import files into.
- Right click on your database and select Tasks > Import Data…
- The SQL Server Import and Export Wizard dialog box will pop-up. Click Next.
- Click on the Data Source drop-down box, and choose Flat File Source from the list. Then click Browse… and select the Delimited text file you want to import. See Figure 1.
- Keep the Format: drop-down box as Delimited, and change the Header row delimiter, Header rows to skip, to correspond with your text file. Click the checkbox if column names are in the first data row.
- Now click on Columns, located in the left-hand side list box. Make sure the Row and Column delimiters are set correctly. For instance, I am using tab delimited text file so I want the Column delimiter to be set to Tab {t}.
- Now click on Advanced, located in the left-hand side list box. Make sure all of your columns show up in column list box. If they don’t all show up (due to some columns in your text file being null), then click on the New button to add a column. Now configure the properties of each column to correspond with the data you're importing. Check each column and change the OutputColumnWidth, ColumnDelimiter, DataType and Name to match up with the delimited columns in the text file you are importing. See Figure 2.
- Now click on Preview, located in the left-hand side list box and double check to make sure you are importing the data how you want, with the correct amount of columns.
- Click on Next, and then choose the Database you want to import the data into.
- Click Next to move to the Select Source Tables and Views. See Figure 3.
- Under the Destination header, you can click on the default table to change it to an existing table in your database. Leave the default if you want to create a new table, but if you are appending data to an existing table you will want to change it to the table you want to use.
- Now click on the Edit Mappings button and make sure the mapping properties are what you want, make any changes necessary. See Figure 4. Click OK when finished.
- Click Next, and leave Execute immediately checked.
- Click Next, and then click Finish, to start performing the import operation.
If all goes well you won't receive any errors during the import operation and the delimited text file data will have been successfully imported into a SQL Server 2005 database table.