Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
As etapas a seguir abrangem como configurar um banco de dados do Azure SQL para uso
com o Datastream.
Para configurar um banco de dados do Azure SQL:
Ative captura de dados alterados (CDC) no seu banco de dados de origem do Azure SQL. Para fazer isso,
conecte-se ao banco de dados usando o Azure Data Studio ou o SQL Server Management Studio
e execute o seguinte comando:
EXECsys.sp_cdc_enable_db;
GO
Ative a CDC nas tabelas em que você precisa capturar mudanças:
EXECsys.sp_cdc_enable_table
@source_schema=N'SCHEMA_NAME',
@source_name=N'TABLE_NAME',
@role_name=NULL
GO
Substitua:
SCHEMA_NAME: o nome do esquema ao qual as tabelas pertencem
TABLE_NAME: o nome da tabela para a qual você quer ativar o CDC.
Ative o isolamento de snapshots.
Ao preencher dados do seu banco de dados do SQL Server, é importante garantir
instantâneos consistentes. Se você não aplicar as configurações descritas nesta
seção, as alterações feitas no banco de dados durante o processo de preenchimento podem levar a
duplicados ou resultados incorretos, especialmente para tabelas sem chaves primárias.
Ativar o isolamento de snapshots cria uma visualização temporária do seu banco de dados no início
do processo de preenchimento. Isso garante que os dados copiados permaneçam consistentes,
mesmo que outros usuários estejam fazendo alterações nas tabelas ao vivo ao mesmo tempo.
Ativar o isolamento de snapshots pode ter um pequeno impacto no desempenho, mas é
essencial para a extração de dados confiável.
Para ativar o isolamento de snapshots:
Acesse o banco de dados com um cliente do SQL Server.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-08-12 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)."]]