title | description | author | ms.author | ms.reviewer | ms.date | ms.service | ms.subservice | ms.topic | dev_langs | monikerRange | |
---|---|---|---|---|---|---|---|---|---|---|---|
sys.sp_copy_data_in_batches (Transact-SQL) |
Copies data from the source table to the target table after verifying that their schema is identical in terms of number of columns, column names and their data types. |
VanMSFT |
vanto |
randolphwest |
03/07/2025 |
sql |
system-objects |
reference |
|
=azuresqldb-current || >=sql-server-ver16 || >=sql-server-linux-ver16 |
[!INCLUDE SQL Server 2022 Azure SQL Database]
Copies data from the source table to the target table after verifying that their schema is identical in terms of number of columns, column names and their data types. TRANSACTION ID
, SEQUENCE NUMBER
, and GENERATED ALWAYS
columns are ignored since they're system generated and this allows copying data from a regular table to a ledger table and vice versa. Indexes between the tables can be different but the target table can only be a heap or have a clustered index. The data is copied in batches in individual transactions. If the operation fails, the target table is partially populated.
For more information on database ledger, see Ledger.
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions
sp_copy_data_in_batches
[ @source_table_name = ] N'source_table_name'
, [ @target_table_name = ] N'target_table_name'
[!INCLUDE extended-stored-procedures]
The name of the table to be used as the source of the data copy.
The name of the table to be used as the target of the data copy.
0 (success)
None.
This operation requires SELECT on the source table, INSERT in the target table, and ALTER on the target table if there are foreign key or check constraints that will be disabled, or an identity column that will be adjusted.