Sometimes, it is necessary to export or import large amounts of data into or out of a database. Those operations are called bulk export and import operations.
SQL Server provides tools to perform bulk import and export and bulk copy operations:
This article explains how to copy large amounts of data from one table or set of tables to other databases using these tools and using ApexSQL Script and ApexSQL Data Diff.
The Import and export wizard creates an Integration Services (SSIS) package that can be scheduled to run on a specified basis and modified by using SQL Server Data Tools.
To start the Import and export wizard, right-click the database and select the Tasks sub-menu -> Export data command:
Note that the SQL Server import and export wizard will not treat an identity column differently than any other column and it will fail when trying to insert data into a table that has an identity column:
If a source table has a foreign key constraint note that the SQL Server import and export wizard does not load tables a specific order for constraints, and it is possible that a table containing a foreign key will get loaded before a table containing a referenced primary key, which will cause a foreign key constraint failure.
bcp utility
The bcp utility is a command-line tool that enables bulk export of data from a source database to a file or bulk data import from a file into a destination database. For example, to export all EmployeeIDs and Emails to the Emails.txt file from the EmployeeEmail table in the TestDB database, run the following bcp command:
bcp TestDB.dbo.EmployeeEmail out Emails.txt –c -T
The -c option specifies that the utility is being used with character data and that the -T option states a trusted connection, meaning that the bcp utility uses the login credentials of the user that is currently logged. If the -T option is not specified a username and password must be specified with the -U and -P options.
The table must exist prior to the import. Before the data is imported into a destination table, the table in a destination instance has to have columns that match the data type to be imported. To insert data from the Emails.txt file into the NewSchema.dbo.EmployeeEmail table use the following bcp command:
bcp NewSchema.dbo.EmployeeEmail in Emails.txt -T –c
The bcp utility can only export data to a file or import data from a file. The security principal must have Select permission on the source table to use the utility.
Import data by using the Bulk insert statement
To import data from a specified file to a table, the Bulk insert statement can be used. Same as the bcp utility, the destination table has to exist and to have column types that match the datatypes that will be imported.
Specify the destination table and the location of the file from which to import the data:
BULK INSERT TestRemote.dbo.EmployeeEmail FROM 'C:\Users\Lenovo\Desktop\Emails.txt'; GO
Import data by using the Openrowset(Bulk) function
The Openrowset(Bulk) function connects to an OLE DB data source to restore data and it allows access to a remote data by connecting to a remote data source.
INSERT INTO AllEmails(Email) SELECT * FROM OPENROWSET( BULK 'C:\Users\Lenovo\Desktop\Emails.txt', SINGLE_BLOB) AS x;
The Openrowset(Bulk) function provides an alternative to accessing objects from a linked server and it is suitable for one-off entry of data from a remote source.
Import and export data by using Select into statement
When the Into clause is used in a combination with the Select statement enables creating a new table based on the result set of the Select statement. For example, to copy the EmployeeEmail table, on the same instance, in the default schema of the TestDB database, run the following query:
SELECT * INTO TestDB.dbo.EmployeeEmail FROM AdventureWorks2012.HumanResources.EmployeeEmail;
Select into cannot be used to create a new table on a remote SQL Server instance, but remote source can be included in the Select statement, if there is a link to the remote instance.
If the source table contains any constraints, indexes, and triggers they will not be transferred to the new table. The column in the newly created table will not inherit the Identity property from the query output if the Select statement contains an aggregate function, the Join clause, or the Group by clause, and if the identity column is used in an expression, used more than once, or is from a remote data source.
Using ApexSQL Script, a SQL Server database migration tool, make a SQL script to export data, or both data and structure, from a source instance and execute it on a destination instance to import data.
To script database data using ApexSQL Script, follow these steps:
Run ApexSQL Script
Once everything is set, click the Load button in the bottom-right corner of the New project window
If there are any dependent objects, these will be shown and checked by default in the Dependencies step
If a destination table already exists and it has the same structure as the source table, use ApexSQL Data Diff, a SQL data compare tool, that can copy data from one table or tables to a destination database table or tables.
To copy data with ApexSQL Data Diff, follow these steps:
Useful resources: bcp Utility SQL Server Import and Export Wizard Bulk Import and Export of Data (SQL Server)
"© 2025 Quest Software Inc. ALL RIGHTS RESERVED. Terms of Use Privacy Cookie Preference Center