For content related to lớn the Import & Export Wizard, see SQL server Import & Export Wizard.Bạn đã xem: phương pháp import tệp tin .sql vào sql server

Import Flat file Wizard is a simple way lớn copy data from a flat tệp tin (.csv, .txt) lớn a new table in your database. The Import Flat tệp tin Wizard supports both comma-separated và fixed width format files. This overview describes the reasons for using this wizard, how lớn find this wizard, và a simple example lớn follow.

Bạn đang xem: Hướng dẫn import file .sql vào sql server

Why would I use this wizard?

This wizard was created khổng lồ improve the current import experience leveraging an intelligent framework known as Program Synthesis using Examples (PROSE). For a web1_user without specialized tên miền knowledge, importing data can often be a complex, error prone, & tedious task. This wizard streamlines the import process as simple as selecting an input đầu vào file & unique table name, and the PROSE framework handles the rest.

PROSE analyzes data patterns in your input đầu vào file to lớn infer column names, types, delimiters, và more. This framework learns the structure of the file & does all of the hard work so web1_users don"t have to.

To further understand the web1_user experience improvement of the Import Flat tệp tin Wizard, check out this video:

Prerequisites

This feature is available on SQL vps Management Studio (SSMS) v17.3 or later. Make sure you are using the latest version. You can find the latest version here.

Getting Started

To access the Import Flat file Wizard, follow these steps:

Open SQL hệ thống Management Studio.Connect to an instance of the SQL vps Database Engine or localhost.Expand Databases, right-click a database (test in the example below), point khổng lồ Tasks, and click Import Flat File above Import Data.


*

To learn more about the different functions of the wizard, refer to the following tutorial:

Tutorial

For the purposes of this tutorial, feel miễn phí to use your own flat file. Otherwise, this tutorial is using the following CSV from Excel, which you are free to copy. If you use this CSV, title it example.csv & make sure khổng lồ save it as a csv in an easy location such as your desktop.


*

Overview:

Step 1: Access Wizard & Intro Page

Access the wizard as described here.


*

Step 2: Specify input đầu vào File

Click browse to select your đầu vào file. At default, the wizard searches for .csv & .txt files. PROSE will detect if the file is comma-separated or fixed-width format regardless of file extension.

Xem thêm: Lắp Ráp Ampli Diy - Giao Lưu, Trao Đổi Hướng Dẫn

The new table name should be unique, and the wizard does not allow you to move further if not.


*

Step 3: Preview Data

The wizard generates a preview that you can view for the first 50 rows. If there are any problems, click cancel, otherwise proceed lớn the next page.


*

Step 4: Modify Columns

The wizard identifies what it believes are the correct column names, data types, etc. Here is where you can edit the fields if they are incorrect (for example, data type should be a float instead of an int).

Columns where empty values are detected will have "Allow Nulls" checked. However if you expect nulls in a column và "Allow Nulls" is not checked, here is where you can update the table definition to lớn allow nulls in one or all columns.

Proceed when ready.


Step 5: Summary

This is simply a summary page displaying your current configuration. If there are issues, you can go back lớn previous sections. Otherwise, clicking finish attempts the import process.


Step 6: Results

This page indicates whether the import was successful. If a green kiểm tra mark appears, it was a success, otherwise you may need to review your configuration or input file for any errors.


Troubleshooting

The Import Flat tệp tin Wizard detects the data types based on the first 200 rows. In scenarios where data further in the flat tệp tin does not conform to the automatically detected data types, an error will occur during import. The error message would be similar to lớn the following:

Error inserting data into table. (gameviethot.com.SqlServer.Prose.Import)The given value of type String from the data source cannot be converted lớn type nvarchar of the specified target column. (System.Data)String or binary data would be truncated. (System.Data)Tactics khổng lồ alleviate this error:


Error inserting data into table occured while inserting rows 1 - 2. (gameviethot.com.SqlServer.Prose.Import)The given value of type String from the data source cannot be converted to lớn type float of the specified target column. (System.Data)Failed khổng lồ convert parameter value from a String to lớn a Double. (System.Data)

Learn More

Learn more about the wizard.