The SQL Server Data Import Wizard (officially known as the SQL Server Import and Export Wizard) is a graphical tool used to move data from a variety of sources—such as Excel, Flat Files (CSV), or other SQL databases—into a SQL Server database. It achieves this by mapping the source columns to destination table columns, handling the data type conversions, and executing the bulk insert process without requiring the user to write complex T-SQL scripts. This is essential for analysts and developers who need to migrate legacy data or import periodic reports into a structured environment for querying.
What You'll Need
- SQL Server Management Studio (SSMS) installed on your workstation.
- Administrative or Write permissions for the destination database.
- The source data file (e.g., .csv, .txt, or .xlsx) saved in a location accessible by the server.
- Appropriate drivers for the source data (such as the Microsoft Access Database Engine for Excel files).
- The server name and authentication credentials (Windows or SQL Server Authentication) for the target instance.
Step-by-Step
- Launch the Wizard: Open SQL Server Management Studio (SSMS) and connect to your database engine. In the Object Explorer, right-click on the specific database where you want the data to land. Navigate to Tasks > Import Data. Note that menu labels may differ slightly depending on your version of SSMS or regional settings.
- Choose a Data Source: In the first screen of the wizard, click the Data source dropdown menu. Select the provider that matches your file. For a CSV or text file, choose "Flat File Source". For an Excel spreadsheet, choose "Microsoft Excel". After selecting the provider, click Browse to locate your file on the local drive or network share. If importing a Flat File, ensure you specify whether the file is delimited (by commas or tabs) and if the data has column names in the first row.
- Configure Source Details: If you chose a Flat File, use the "Columns" tab on the left sidebar to verify that the wizard has correctly identified the column boundaries. You can manually adjust the column delimiters or row qualifiers here. If the data looks shifted or merged, double-check your delimiter settings before proceeding.
- Choose a Destination: Click Next to reach the Destination screen. From the dropdown, select "SQL Server Native Client" or "Microsoft OLE DB Driver for SQL Server". Ensure the Server name is correct. Choose your authentication method (Windows Authentication is standard for local domains; SQL Server Authentication requires a username and password). Finally, select the target database from the dropdown list.
- Specify Table Copy or Query: You will be asked whether you want to copy data from one or more tables or provide a query to specify the data to transfer. For most standard imports, select "Copy data from one or more tables or views". This is the simplest method for moving an entire file into a new or existing table.
- Map Source to Destination: You will now see a list of source tables (or files) and their corresponding destination tables. You can click on the destination table name to rename it. For example, if your Excel sheet is named "Sheet1$", you might rename it to "Customer_Imports_2023". Click the "Edit Mappings" button to ensure the data types match. For instance, if the source is a long string of text, ensure the destination is set to nvarchar(max) or a sufficiently large length to avoid truncation errors.
- Review Data Type Conversions: Within the Edit Mappings dialog, check the "Type" column. The wizard attempts to guess the data type based on the first few rows of your file. If a column contains numbers but the wizard labels it as a string, you can change it here, though it is often safer to import as a string and convert it using a SQL view later to avoid "Data Type Mismatch" failures.
- Select Run Options: Choose whether to "Run immediately" or "Save SSIS Package". Running immediately executes the import right now. Saving the package allows you to run this import as a scheduled job later via SQL Server Integration Services (SSIS). Most one-time imports should select "Run immediately".
- Execute and Verify: Click Finish. The wizard will provide a progress window showing the number of rows transferred for each table. If the process completes successfully, you will see a "Success" message. If it fails, the wizard will list the specific row or column that caused the error.
- Final Validation: Go back to SSMS, right-click your tables folder, and select Refresh. Run a simple SELECT TOP 100 query on the newly created table to ensure the data is formatted correctly and no characters were lost during the import.
Common Mistakes
One of the most frequent errors is ignoring the "Edit Mappings" step. By default, the wizard may assign a length of 50 characters to a column. If your source data contains a field with 60 characters, the entire import will fail with a "Truncation Error". Always check your longest expected strings and increase the destination length accordingly.
Another common mistake is importing data into a table that already exists without checking for primary key conflicts. If the destination table has a Primary Key or Unique Constraint and your source file contains duplicate IDs, the wizard will crash mid-process. It is often better to import data into a "staging table" (a temporary table with no constraints) and then use a SQL script to merge the data into the final production table.
Users also frequently forget to close the source file before starting the wizard. If you have an Excel file open in the Excel application, the wizard may be unable to obtain a lock on the file, resulting in an "External table is not accessible" error.
Tips
To handle extremely large datasets, avoid importing directly into a table with many indexes. Indexes slow down the insertion process because SQL Server must update the index for every single row added. Instead, import the data into a heap table (a table without a clustered index), and then create your indexes after the data is fully loaded.
When dealing with CSV files, always check the encoding. If your data contains special characters or non-English symbols, ensure the "Code page" in the Flat File Source settings is set to UTF-8 or the appropriate regional encoding. Otherwise, those characters will appear as question marks or garbled text in your database.
If you are importing from Excel and encounter a 32-bit vs 64-bit driver conflict, try launching the "SQL Server Import and Export Wizard (64-bit)" or "(32-bit)" directly from the Windows Start Menu rather than launching it through SSMS. The version of the wizard you use must match the architecture of the installed Excel drivers.
Troubleshooting
If the import fails, start by checking the error log provided at the end of the wizard. Look for the specific error code. If you see a "Data truncation" error, return to the mapping step and increase the character length of the affected column.
If you receive a "Permission Denied" error, ensure that the account running the wizard has the "bulk insert" permission on the server. If you are importing a file from a network drive, the SQL Server service account (not just your user account) may need read access to that folder.
In cases where the wizard cannot connect to the server, verify that the SQL Server Browser service is running and that the firewall allows traffic on port 1433. If you are using a named instance (e.g., SERVER\SQLEXPRESS), ensure the instance name is typed exactly as it appears in the connection manager.
If the data types are completely mismatched and the wizard refuses to map them, the safest route is to import all columns as nvarchar(max). Once the data is inside SQL Server, you can use the CAST or CONVERT functions in a new table to move the data into the correct numeric or date formats.
Frequently Asked Questions
Can I import data from a website or API?
No, the Import and Export Wizard is designed for static files and other databases. To get data from an API, you would need to use a script (like Python or PowerShell) or a full SSIS package with an HTTP connection manager.
Why does the wizard say my Excel file is not a valid source?
This usually happens because the required Access Database Engine driver is missing or the bit-version (32-bit vs 64-bit) of the driver does not match the version of the wizard you are running.
Can I update existing rows or only add new ones?
The wizard is primarily for "appending" or "creating" tables. It does not perform an "Upsert" (Update or Insert). To update existing rows, import the data into a temporary staging table and then run an UPDATE JOIN query.
Is there a limit to how many rows I can import?
There is no hard row limit, but very large files (millions of rows) can exhaust your transaction log. For massive datasets, consider using the BCP (Bulk Copy Program) command-line tool for better performance.
What is the difference between a Flat File and a CSV?
A CSV (Comma Separated Values) is a specific type of Flat File. In the wizard, you use the "Flat File Source" for both; you simply specify the comma as the delimiter for CSVs.
How do I handle dates that are in a non-standard format?
The wizard can be picky about date formats. If your dates are not in a standard ISO format, import them as text (nvarchar) first, then use the SQL TRY_CONVERT function to transform them into date types within the database.