Import SQL Server database data using SSMS

Updated at:

SQL Server Management Studio (SSMS) is an integrated development environment (IDE) for accessing, configuring, and managing SQL Server databases. For data migration, backup, or recovery, you can use SSMS to import data from a source Web Hosting database to a destination Web Hosting database to maintain data integrity.

Prerequisites

  • SSMS is installed. You can download the installation package from the official Microsoft website.

    Note

    This topic uses SSMS version 18.10 as an example. The user interface may vary in other versions.

  • The source Web Hosting database contains data, such as data tables, views, and functions.

Background information

  • This topic uses a SQL Server 2008 database on a Windows-based Web Hosting instance as an example for both the source and destination databases. In this example, data is migrated by exporting an SQL script from a data table in the source database.

  • Before you import data, familiarize yourself with the following basic concepts of SQL Server databases:

    • A database can contain multiple objects, such as data tables, stored procedures, views, and functions.数据表

    • A data table consists of rows of data. For example, article content is stored in a data table.数据表截图

    • A view is a virtual data table whose data is derived from one or more physical data tables. For example, you can combine three tables into a single view to simplify queries.视图信息

    • A stored procedure or a function is a reusable set of SQL statements that extends the capabilities of the SQL language.

      The following script is an example of a stored procedure:

      存储过程

      The following script is an example of a function:

      函数

Procedure

  1. Obtain the database information.
    1. Log on to the Web Hosting console.
    2. Find the target Web Hosting instance and click Manage in the Actions column.
    3. In the left-side navigation pane, click Database Information.
    4. On the Database Information page, record the connection details.
      Note If you forget the database password, you can reset it. For more information, see Reset the password of a Web Hosting database.
      获取windows数据库
  2. Remotely connect to the destination Web Hosting database using SSMS.

    1. On your local host, open SQL Server Management Studio.

    2. In the Connect to Server dialog box, configure the connection settings and click Connect.

      连接服务器

      The following table describes the parameters.

      Parameter

      Description

      Server type

      Keep the default value, Database Engine.

      Server name

      Enter the database address of your Web Hosting instance.

      Authentication

      Keep the default value, SQL Server Authentication.

      Username

      Enter the username for your Web Hosting database.

      Password

      Enter the password for your Web Hosting database.

      After you connect, the database node appears in the left navigation pane.

  3. Use SSMS to export the data table from the source Web Hosting database as an SQL script and save it locally.

    This example covers exporting a data table script; the method is similar for other database objects.

    For detailed instructions, see Export SQL Server database data by using SSMS.

  4. Execute the exported SQL script on the destination database.

    1. Use SQL Server Management Studio to open the exported data table script from the source Web Hosting.

    2. In the left-side navigation pane of SSMS, select the destination Web Hosting database node.

    3. On the SSMS toolbar, click New Query.

      A new query editor window opens.

      脚本编辑窗口

      The following table describes the areas in the figure.

      Area

      Description

      The name of the destination database node for which you are editing the script.

      The query editor for the destination Web Hosting database node.

      The query editor for the source database data.

    4. Copy the contents of the exported script and paste them into the new query editor window. Then, delete the first line of the script (the USE [database_name] statement).

    5. On the SSMS toolbar, click Execute.

      After the script executes, a success message appears in the Messages tab.

      脚本执行

      In the left-side navigation pane, the imported data table schema now appears under the destination Web Hosting database node.

  5. Import the data from the source database tables into the destination Web Hosting database.

    1. In the navigation pane on the left of SSMS, right-click the destination Web Hosting database node and select Tasks (T) > Import Data (I)....Import data

    2. On the welcome page of the SQL Server Import and Export Wizard, click Next.

    3. On the Choose a Data Source page, configure the data source parameters and click Next.

      源数据配置

      The following table describes the key parameters.

      Parameter

      Description

      Data source

      Select SQL Server Native Client 11.0.

      Server name

      Enter the endpoint of the source Web Hosting database. For information about how to obtain the database endpoint, see Step 1.

      Authentication

      Select Use SQL Server Authentication.

      • User name: Enter the username of the source Web Hosting database. For information about how to obtain the database username, see Step 1.

      • Password: Enter the password for the source Web Hosting database. If you forget the password, you can reset it. For more information, see Reset the password of a Web Hosting database.

      Database

      Enter the name of the source Web Hosting database. For information about how to obtain the database name, see Step 1.

    4. On the Choose a Destination page, configure the destination database information and click Next.

      目标数据配置

      The following table describes the key parameters.

      Parameter

      Description

      Destination

      Select SQL Server Native Client 11.0.

      Server name

      Enter the endpoint of the destination Web Hosting database. For information about how to obtain the database endpoint, see Step 1.

      Authentication

      Select Use SQL Server Authentication.

      • User name: Enter the username of the destination Web Hosting database. For information about how to obtain the database username, see Step 1.

      • Password: Enter the password for the destination Web Hosting database. If you forget the password, you can reset it. For more information, see Reset the password of a Web Hosting database.

      Database

      Enter the name of the destination Web Hosting database. For information about how to obtain the database name, see Step 1.

    5. On the Specify Table Copy or Query page, select Copy data from one or more tables or views and click Next.

    6. On the Select Source Tables and Views page, in the Source column, select the checkboxes复选框 for the data tables to import. Verify that the corresponding table names appear in the Destination column, and then click Next.目标数据

    7. Click Edit Mappings.... In the Column Mappings dialog box, select Delete rows in destination table and Enable identity insert, and then click OK.列映射

    8. On the Select Source Tables and Views page, click Next.

    9. On the Save and Run Package page, click Next. On the Complete the Wizard page, click Finish.

Results

When the import process is complete and the status shows Execution was successful, click Close, as shown in the following figure. You can then view the content of the imported data tables under the destination Web Hosting database node.

导入成功