SQL Server データベースからデータをバックフィルする際は、整合性のあるスナップショットを確保することが重要です。このセクションで説明している設定を適用しない場合、バックフィル プロセス中にデータベースに加えた変更により、特に主キーのないテーブルでは、重複や誤った結果が生じる可能性があります。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 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)."]]