Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Langkah-langkah berikut membahas cara mengonfigurasi database Azure SQL untuk digunakan
dengan Datastream.
Untuk mengonfigurasi database Azure SQL:
Aktifkan pengambilan data perubahan (CDC) untuk database Azure SQL sumber Anda. Untuk melakukannya,
hubungkan ke database menggunakan Azure Data Studio atau SQL Server Management Studio
dan jalankan perintah berikut:
EXECsys.sp_cdc_enable_db;
GO
Aktifkan CDC pada tabel yang perubahannya perlu Anda rekam:
EXECsys.sp_cdc_enable_table
@source_schema=N'SCHEMA_NAME',
@source_name=N'TABLE_NAME',
@role_name=NULL
GO
Ganti kode berikut:
SCHEMA_NAME: nama skema tempat tabel berada
TABLE_NAME: nama tabel yang ingin Anda aktifkan CDC-nya
Aktifkan isolasi snapshot.
Saat Anda mengisi ulang data dari database SQL Server, penting untuk memastikan
snapshot yang konsisten. Jika Anda tidak menerapkan setelan yang dijelaskan di bagian
ini, perubahan yang dilakukan pada database selama proses pengisian ulang dapat menyebabkan
duplikat atau hasil yang salah, terutama untuk tabel tanpa kunci utama.
Mengaktifkan isolasi snapshot akan membuat tampilan sementara database Anda di awal
proses pengisian ulang. Tindakan ini memastikan bahwa data yang disalin tetap konsisten,
meskipun pengguna lain membuat perubahan pada tabel aktif secara bersamaan.
Mengaktifkan isolasi snapshot mungkin memiliki sedikit dampak pada performa, tetapi hal ini
penting untuk ekstraksi data yang andal.
Untuk mengaktifkan isolasi snapshot:
Hubungkan ke database Anda menggunakan klien SQL Server.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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)."]]