Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
I passaggi seguenti illustrano come configurare un database Azure SQL per l'utilizzo con Datastream.
Per configurare un database Azure SQL:
Attiva la funzionalità Change Data Capture (CDC) per il database Azure SQL di origine. Per farlo,
connettiti al database utilizzando Azure Data Studio o SQL Server Management Studio
ed esegui il seguente comando:
EXECsys.sp_cdc_enable_db;
GO
Abilita la CDC nelle tabelle di cui devi acquisire le modifiche:
EXECsys.sp_cdc_enable_table
@source_schema=N'SCHEMA_NAME',
@source_name=N'TABLE_NAME',
@role_name=NULL
GO
Sostituisci quanto segue:
SCHEMA_NAME: il nome dello schema a cui appartengono le tabelle
TABLE_NAME: il nome della tabella per cui vuoi attivare la CDC
Attiva l'isolamento degli snapshot.
Quando esegui il backfill dei dati dal database SQL Server, è importante garantire screenshot coerenti. Se non applichi le impostazioni descritte in questa
sezione, le modifiche apportate al database durante il processo di backfill potrebbero portare a risultati duplicati o errati, in particolare per le tabelle senza chiavi primarie.
L'attivazione dell'isolamento degli snapshot crea una visualizzazione temporanea del database all'inizio del processo di backfill. In questo modo, i dati copiati rimangono coerenti anche se altri utenti apportano modifiche alle tabelle in tempo reale contemporaneamente.
L'attivazione dell'isolamento degli snapshot potrebbe avere un lieve impatto sulle prestazioni, ma è obbligatoria per un'estrazione dei dati affidabile.
Per attivare l'isolamento degli snapshot:
Connettiti al database utilizzando un client SQL Server.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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)."]]