SQL Server6 min read

How to Export SQL Server Table Schema and Data: 4 Methods

Admin
Updated:

Quick Answer

Export SQL Server table schema and data in 4 ways.

Export Wizard and Generate Scripts cover small jobs.

BACPAC and SQL Server Migrator cover larger moves.

Export Wizard moves rows but does not rebuild your table design.

Generate Scripts and BACPAC carry schema and data together.

Migrator reads MDF files and exports to MySQL or Azure.

You need to export SQL Server table schema and data when you move a database to a new server, build a test copy or share a table with another team. Schema means the structure. Data means the rows inside it.

Many admins export rows and forget the keys, indexes and defaults. The new server then holds data with a weak structure.

This guide compares 4 methods, shows the exact SSMS path for every method and states what it leaves behind.

Which Method Exports SQL Server Table Schema and Data Best?

Method

Moves schema

Moves data

Good for

Import and Export Wizard

Basic table shape

Yes

Quick row copies between tables

Generate Scripts

Yes

Yes

Small databases and script files

BACPAC export

Yes

Yes

Moves to another instance or Azure SQL Database

SQL Server Migrator

Yes

Yes

MDF files, MySQL, Azure SQL Server and damaged files

Select the method by size and source. A live server with a few tables fits the first three methods. An offline MDF file or a damaged database fits SQL Server Migrator.

How to Export Table Data With the Import and Export Wizard?

Suits: Admins and analysts. Needs: SSMS and read access to the source database. Limit: It focuses on data and not on every object.

  1. Connect to the instance in SQL Server Management Studio and expand Databases.
  2. Right click the database, select Tasks and then select Export Data.
  3. Choose the source, set the destination server and database and select the tables.
  4. Review the column mapping and finish the wizard.

The wizard copies rows well. Create the target tables with the right keys and indexes first if you want the same structure on the new server. Microsoft describes the wizard in its Import and Export Wizard guide.

How to Export Schema and Data With Generate Scripts?

Suits: Admins who want a plain script file. Needs: SSMS and permission to script the database. Limit: Script files grow fast with table size.

  1. Right click the database in Object Explorer, select Tasks and then select Generate Scripts.
  2. Select the tables or objects that you need.
  3. On the scripting options page, set Types of data to script to Schema and data. The default is Schema only.
  4. Save the output as a single script file or one file per object.
  5. Execute the script on the target server in a query window.

The wizard continues past errors only if you set Continue scripting on error to True. The default stops at the first error, so check the log after the export.

How to Export Schema and Data to a BACPAC File?

Suits: Admins who move a database to another instance or Azure SQL Database. Needs: SSMS and VIEW DEFINITION permission. Limit: Databases with unsupported objects or users cannot export.

A BACPAC file holds object definitions and all table data. You can import it into another SQL Server instance or Azure SQL Database.

  1. Right click the database, select Tasks and then select Export Data-tier Application.
  2. Save the file to local disk or to Azure.
  3. Use Advanced to select a subset of tables when you do not need all of them.
  4. Select Import Data-tier Application on the target instance and open the BACPAC file.

Microsoft lists the limits in its guide to exporting a data-tier application.

How to Export SQL Server Data With SQL Server Migrator?

Suits: Admins who want one wizard for many targets. Needs: A Windows PC and a live server login or an MDF file. Limit: The free demo exports 25 records per table and 5 other categories.

SQL Server Migrator moves schema and records from a live server or an MDF file to another SQL Server database, SQL script files, Azure SQL Server or a MySQL database.

Export SQL Server Schema and Data in One Wizard

SQL Server Migrator opens live servers and offline MDF files, previews tables, views and procedures and exports schema only or schema with data.

Download Now Purchase Now

  1. Select Open and choose Online to add a live server or Offline to load an MDF file.
  2. Preview tables, views, procedures and rules. Deleted items show in red.
  3. Select the export target and enter the server details.
  4. Choose Schema only or Schema with data and start the export.

Marking single objects works in live mode. Offline mode migrates every object in the MDF file. For Azure, create the target database first and add your client IP to the server firewall. Microsoft states that connections fail when the client IP matches no rule, as the Azure SQL firewall guide explains.

A damaged source file needs repair before export. Advance Scan mode repairs the MDF file before migration. Try SQL Recovery for severe damage and read about object level recovery.

Best Practices Before You Export a Database

  • Back up the source database and verify the backup first.
  • Create the target database and set collation to match the source.
  • Test the export on one small table before you start a large job.
  • Compare row counts on both servers after the export.
  • Execute DBCC CHECKDB on the target after the load. See DBCC CHECKDB not working if errors appear.

Author's Verdict

Use the Export Wizard for quick row copies, Generate Scripts for small databases and BACPAC for a clean move between instances. Choose SQL Server Migrator for an MDF source, a damaged database, a MySQL target or an Azure target. Always compare row counts after the export.

FAQs on SQL Server Export

Does the Export Wizard Copy Keys and Indexes?

No, the wizard focuses on data. Create the target tables first when you need the same keys and indexes.

How Do I Export Both Schema and Data With Generate Scripts?

Set Types of data to script to Schema and data on the scripting options page. The default is Schema only.

Can I Export a Damaged MDF File?

Yes, Advance Scan mode repairs a damaged MDF file before migration.

Does SQL Server Migrator Need a Connected Server?

No, offline mode opens an MDF file on a PC with no server connection. A live export needs server details.

Can I Send Data to MySQL?

Yes, the software exports tables, views and other objects to a MySQL database.

Can I Migrate to Azure SQL Database?

Yes, create the Azure database first and add your client IP to the server firewall before you connect.

Do I Get Script Files From the Export?

Yes, the software writes database objects to SQL script files for later use.