SSMS Import Flat File Feature

The Import Flat File feature in SSMS (SQL Server Management Studio) was introduced in December 2017 (14.0.17213.0). This is a streamlined version of the Import Data feature and it minimizes the user intervention during a file import.

Unlike the Import and Export Data Feature, you don’t have the option to save the import as a .DTS package for SSIS. This makes the Import Flat File method a good one for quick imports of individual files to SQL Server, but not so much if it’s a repetitive task you want to automate it.

In this guide, we will walk through the process of importing a CSV file into a SQL Server database using the Import Flat File feature!


How to a Import Flat File to SQL Server

To import a flat file into a SQL Server database table, we can use the Import Flat File Feature in SQL Management Studio (SSMS).

Once you have SSMS open, we need to identify the database we are restoring to. For this demo, I’m creating a new test database:

Create Test Database SQL Server

Now, onto the Flat File import.

Step 1: Right-click your destination database, select Tasks and Import Flat File.

SSMS Tasks Import Flat File

Step 2: Click Next to continue in the Flat File Wizard.

Import Flat File Wizard

Step 3: Browse to the file, enter the desired table name and amend the schema name accordingly.

SSMS Wizard Input File

Step 4: Preview the data on the next window and click Next when you are happy.

SSMS Import Data Wizard Preview Data

Step 5: Review Column Names/Primary Keys/NULLs, and take as much time as you need when selecting Data types!

SSMS File Import Data Types

Step 6: Finish up the Import Flat File Wizard.

SSMS Flat File Import Summary

Uh-oh! You might see an error message like this.

SSMS File Import Error

Data type conversion errors are common when importing and exporting data. It is important to pay attention to any error messages that appear during the import process. In case of errors, you can search the .csv file for the value mentioned in the error message, to identify the column that needs to be modified.

Error inserting data into table. (Microsoft.SqlServer.Import.Wizard)
The given value of type Decimal from the data source cannot be converted to type decimal of the specified target column. (System.Data)
Parameter value '101.8936' is out of range.
The given value of type Decimal from the data source cannot be converted to type decimal of the specified target column

I’m now searching the CSV for this value.

Searching CSV File for Value

Step 7: Go back in the wizard to Modify Columns and adjust the data type as needed (e.g., increase decimal precision).

SSMS Import Flat File Change Data Type

Step 8: Now finish the wizard and hope for the best!

SSMS Import Flat File Wizard Complete

Step 9: Verify the data is accurate.

If the data isn’t good, you can try go back and review the data types within the wizard. We should really be using Import and Export Data Feature for the more complex file imports, or SQL Server Integration Services (SSIS).

I hope all this has been useful for you, and you have successfully imported a file to SQL Server!


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts
Categories
Tags

Always On Availability Groups (AAG) (4) AWS (4) AWS Redshift (6) Database Admin (72) Database Backups & Recovery (14) Database Mirroring (2) Error Messages (5) Failover Cluster Instances (FCI) (1) Git Commands (6) Importing & Exporting Data (2) Linked Servers (3) Linux Administration (2) Logging & Monitoring (1) Microsoft Patching (2) MySQL (4) Postgres (6) PowerShell Scripts (2) SQL Certificates & Encryption (3) SQL Server Agent (5) SQL Server CDC (2) SQL Server Data Types (2) SQL Server Management Studio (SSMS) (16) SQL Server Networking (3) SQL Server on Linux (1) SQL Server Patching (2) SQL Server Performance Tuning (6) SQL Server Processes (SPIDs) (7) SQL Server Replication (2) SQL Server Scripts (13) SQL Server Security (4) SQL Server Storage (10) Windows Admin (21) Windows Authentication (2) Windows Automation (1) Windows Events (2) Windows Firewall (4) Windows Subsystem for Linux (WSL) (18)