Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
En los siguientes pasos, se explica cómo configurar una base de datos de Azure SQL para usarla con Datastream.
Para configurar una base de datos de Azure SQL, haz lo siguiente:
Habilita la captura de datos modificados (CDC) para tu base de datos de Azure SQL de origen. Para ello, conéctate a la base de datos con Azure Data Studio o SQL Server Management Studio y ejecuta el siguiente comando:
EXECsys.sp_cdc_enable_db;
GO
Habilita la CDC en las tablas para las que necesitas capturar cambios:
EXECsys.sp_cdc_enable_table
@source_schema=N'SCHEMA_NAME',
@source_name=N'TABLE_NAME',
@role_name=NULL
GO
Reemplaza lo siguiente:
SCHEMA_NAME: Es el nombre del esquema al que pertenecen las tablas.
TABLE_NAME: El nombre de la tabla para la que deseas habilitar la CDC
Habilita el aislamiento de instantáneas.
Cuando reabasteces datos de tu base de datos de SQL Server, es importante garantizar que los instantáneas sean coherentes. Si no aplicas la configuración que se describe en esta sección, los cambios que se realicen en la base de datos durante el proceso de reabastecimiento podrían generar duplicados o resultados incorrectos, en especial para las tablas sin claves primarias.
Si habilitas el aislamiento de instantáneas, se crea una vista temporal de tu base de datos al comienzo del proceso de reabastecimiento. Esto garantiza que los datos que se copian permanezcan coherentes,
incluso si otros usuarios realizan cambios en las tablas activas al mismo tiempo.
Habilitar el aislamiento de instantáneas puede tener un ligero impacto en el rendimiento, pero es esencial para una extracción de datos confiable.
Para habilitar el aislamiento de instantáneas, haz lo siguiente:
Conéctate a tu base de datos con un cliente de SQL Server.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-04 (UTC)"],[[["\u003cp\u003eDatastream requires enabling change data capture (CDC) on your Azure SQL database and specific tables to track data changes.\u003c/p\u003e\n"],["\u003cp\u003eEnabling snapshot isolation on the database is crucial for maintaining data consistency during backfill processes, particularly for tables without primary keys.\u003c/p\u003e\n"],["\u003cp\u003eA dedicated Datastream user must be created with the appropriate permissions (\u003ccode\u003edb_owner\u003c/code\u003e and \u003ccode\u003edb_denydatawriter\u003c/code\u003e) within the Azure SQL database.\u003c/p\u003e\n"],["\u003cp\u003eThe steps needed to enable CDC are done by running the required commands using Azure Data Studio or SQL Server Management Studio.\u003c/p\u003e\n"]]],[],null,["# Configure an Azure SQL database\n\nThe following steps cover how to configure an Azure SQL database for use\nwith Datastream.\n| **Note:** Datastream supports Azure SQL Database only when you use the change tables CDC method.\n\nTo configure an Azure SQL database:\n\n1. Enable change data capture (CDC) for your source Azure SQL database. To do it,\n connect to the database using Azure Data Studio or SQL Server Management Studio\n and run the following command:\n\n EXEC sys.sp_cdc_enable_db;\n GO\n\n2. Enable CDC on the tables for which you need to capture changes:\n\n EXEC sys.sp_cdc_enable_table\n @source_schema = N'\u003cvar translate=\"no\"\u003eSCHEMA_NAME\u003c/var\u003e',\n @source_name = N'\u003cvar translate=\"no\"\u003eTABLE_NAME\u003c/var\u003e',\n @role_name = NULL\n GO\n\n | **Note:** You need to run the command for each table for which you want to enable CDC.\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eSCHEMA_NAME\u003c/var\u003e: the name of the schema to which the tables belong\n - \u003cvar translate=\"no\"\u003eTABLE_NAME\u003c/var\u003e: the name of the table for which you want to enable CDC\n3. Enable snapshot isolation.\n\n When you backfill data from your SQL Server database, it's important to ensure\n consistent snapshots. If you don't apply the settings described in this\n section, changes made to the database during the backfill process might lead to\n duplicates or incorrect results, especially for tables without primary keys.\n\n Enabling snapshot isolation creates a temporary view of your database at the start\n of the backfill process. This ensures that the data being copied remains consistent,\n even if other users are making changes to the live tables at the same time.\n Enabling snapshot isolation might have a slight performance impact, but it's\n essential for reliable data extraction.\n\n To enable snapshot isolation:\n 1. Connect to your database using a SQL Server client.\n 2. Run the following command:\n\n ALTER DATABASE \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eDATABASE_NAME\u003c/span\u003e\u003c/var\u003e SET ALLOW_SNAPSHOT_ISOLATION ON;\n\n Replace \u003cvar translate=\"no\"\u003eDATABASE_NAME\u003c/var\u003e with the name of you database.\n4. Create a Datastream user:\n\n 1. Connect to the `master` database and create a login:\n\n USE master;\n CREATE LOGIN \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eYOUR_LOGIN\u003c/span\u003e\u003c/var\u003e WITH PASSWORD = '\u003cvar translate=\"no\"\u003ePASSWORD\u003c/var\u003e';\n\n 2. Connect to the source database and create a user for your login:\n\n USE \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eDATABASE_NAME\u003c/span\u003e\u003c/var\u003e\n CREATE USER \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eUSER_NAME\u003c/span\u003e\u003c/var\u003e FOR LOGIN \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eYOUR_LOGIN\u003c/span\u003e\u003c/var\u003e;\n\n 3. Assign the `db_owner` and `db_denydatawriter` roles to your user:\n\n EXEC sp_addrolemember 'db_owner', '\u003cvar translate=\"no\"\u003eUSER_NAME\u003c/var\u003e';\n EXEC sp_addrolemember 'db_denydatawriter', '\u003cvar translate=\"no\"\u003eUSER_NAME\u003c/var\u003e';\n\n 4. Grant the `VIEW DATABASE STATE` permission to your user:\n\n GRANT VIEW DATABASE STATE TO \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eUSER_NAME\u003c/span\u003e\u003c/var\u003e;\n\nWhat's next\n-----------\n\n- Learn more about how Datastream works with [SQL Server sources](/datastream/docs/sources-sqlserver)."]]