SQL Server utility objects script reference
Access reference material for the SQL Server utility objects script, including components, parameters, and troubleshooting.
Overview
The script installs versioned utility stored procedures and functions to set up your SQL Server database for ingestion in Lakeflow Connect. Setup tasks include:
- Permission management
- Change tracking (CT) setup
- Change data capture (CDC) setup
- Platform detection
- DDL support object creation for schema change tracking
Version information
- Current Version: 1.7
- Major Version: 1
- Minor Version: 7
- Version Function:
lakeflowUtilityVersion()
What's new in version 1.7
Highlights
- Fixes a data-loss bug in schema evolution. In earlier versions, adding a column to a table that also has a pre-existing (non-Lakeflow) capture instance could ingest the new column as
NULL. This is fixed, along with several related schema-evolution failures (see Bug fixes). - DDL support objects are now optional for change tracking. The DDL audit table and trigger are no longer required for automatic schema evolution and are off by default. Set
@CreateDdlSupportingObjects = 1onlakeflowSetupChangeTrackingonly if you still want them. - More reliable schema evolution. Constraint changes are classified so that non-breaking ones, such as foreign keys, no longer trigger unnecessary full refreshes.
Bug fixes
- Fixed several
ADD COLUMNschema-evolution failures, including tables that use dynamic data masking, case-sensitive or binary collations, and a reinitialization loop or interrupted ingestion when a pre-existing capture instance is present. - Fixed collation-conflict errors on databases with a non-default server collation.
- Fixed DDL triggers that could fail when run from a session with non-default
SEToptions. - Fixed
lakeflowFixPermissionsto grant the required server-scoped permissions from the master database. - Fixed uninstall (
CLEANUPmode) leaving orphaned DDL triggers that could blockALTER TABLE.
Other changes
- Added
@AllowDisablePreExistingCaptureInstancesonlakeflowSetupChangeDataCapture. Set it to1to let Lakeflow Connect take over and manage a table's pre-existing (non-Lakeflow) CDC capture instance instead of leaving it in place.
Key components
Functions
lakeflowDetectPlatform()
Detects the SQL Server platform type.
Returns: 'AZURE_SQL_DATABASE', 'AZURE_SQL_MANAGED_INSTANCE', 'AMAZON_RDS', 'ON_PREMISES', or 'UNKNOWN'
lakeflowUtilityVersion()
Detects the utility objects version.
Returns: '1.7'
Stored procedures
lakeflowFixPermissions
Grants required permissions to users for ingestion operations.
Parameters:
Parameter | Description |
|---|---|
| Required. Username to grant permissions to |
| Optional. Controls table-level permission scope |
@Tables parameter options:
Option | Description |
|---|---|
| Grant only system-level permissions (default) |
| Grant permissions on all user tables in the database |
| Grant permissions on all tables in specified schemas |
| Grant permissions on specific tables |
Wildcard support | Example: |
What it does:
- Grants
SELECTon required system views (sys.objects,sys.tables,sys.columns, etc.) - Grants
EXECUTEon system stored procedures (sp_tables,sp_columns_100, etc.) - Optionally grants
SELECTon user tables based on the@Tablesparameter - Handles platform-specific differences (Azure SQL Database, Managed Instance, RDS, On-premises)
lakeflowSetupChangeTracking
Enables change tracking at the database and table levels, with optional DDL support (opt-in).
Parameters:
Parameter | Description |
|---|---|
| Optional. Tables to enable CT on |
| Optional. User to grant permissions to |
| Optional. CT retention period (default: |
| Optional. |
| Optional. Default |
@Tables parameter options:
Option | Description |
|---|---|
| Set up database-level CT only, no table enablement (also creates DDL support objects when |
| Enable CT on all user tables with primary keys |
| Enable CT on tables in specified schemas |
| Enable CT on specific tables |
Wildcard support | Example: |
What it does:
- Enables change tracking at the database level if not already enabled
- When
@CreateDdlSupportingObjects = 1, creates a versioned DDL audit table (lakeflowDdlAudit_1_7) and a trigger to capture schema changes - Enables CT on specified tables (skips tables without primary keys)
- Grants
VIEW CHANGE TRACKINGpermissions to the specified user CLEANUPmode: Removes DDL support objects
Important behaviors:
- Automatically skips tables without primary keys (CDC is recommended for these)
- Smart discovery with the
'ALL'parameter - Idempotent: Safe to run multiple times
lakeflowSetupChangeDataCapture
Enables CDC at the database and table levels with DDL support and capture instance management.
Parameters:
Parameter | Description |
|---|---|
| Optional. Tables to enable CDC on |
| Optional. User to grant permissions to |
| Optional. |
| Optional. |
@Tables parameter options:
Option | Description |
|---|---|
| Set up database-level CDC and DDL support only |
| Enable CDC on all user tables |
| Enable CDC on tables in specified schemas |
| Enable CDC on specific tables |
What it does:
- Enables CDC at the database level if not already enabled
- Creates a capture instance tracking table (
lakeflowCaptureInstanceInfo_1_7) - Creates helper procedures for capture instance management:
lakeflowDisableOldCaptureInstance_1_7lakeflowMergeCaptureInstances_1_7lakeflowRefreshCaptureInstance_1_7
- Creates an
ALTER TABLEtrigger for automatic schema change handling - Enables CDC on specified tables
- Grants required CDC permissions to the specified user
CLEANUPmode: Removes all CDC DDL support objects
Important behaviors:
- Works with tables with or without primary keys
- Automatically handles capture instance rotation on schema changes
- Idempotent: Safe to run multiple times
Platform support
- On-premises SQL Server (EngineEdition 1-4)
- Azure SQL Database (EngineEdition 5)
- Azure SQL Managed Instance (EngineEdition 8)
- Amazon RDS for SQL Server (detected by server name pattern)
Prerequisites
- User executing the script must be a member of
db_ownerrole - For CT setup: Change tracking must be available on the platform
- For CDC setup: Change data capture must be available on the platform
Installation instructions
Download and run the script
-
Download the latest version of the script:
-
Run the script:
- Open the downloaded script in SQL Server Management Studio (SSMS), Azure Data Studio, or your preferred SQL client.
- Connect to your SQL Server instance.
- Confirm that you are connected to the target database where you want to install the utility objects.
- Run the script.
-
Verify installation:
SQL-- Verify installation
SELECT dbo.lakeflowUtilityVersion() AS UtilityVersion;
SELECT dbo.lakeflowDetectPlatform() AS Platform;
Alternative: Run using the command line
If you prefer to use sqlcmd:
sqlcmd -S YourServerName -d YourDatabase -E -i utility_script.sql
Replace YourServerName and YourDatabase with your actual server and database names. Use -U username -P password instead of -E if not using Windows authentication.
Example: Fix permissions (system only)
-- Grant system permissions only
EXEC dbo.lakeflowFixPermissions
@User = 'myuser';
Example: Fix permissions (with table access)
-- Grant system permissions plus access to all tables
EXEC dbo.lakeflowFixPermissions
@User = 'myuser',
@Tables = 'ALL';
-- Grant permissions for specific schemas
EXEC dbo.lakeflowFixPermissions
@User = 'myuser',
@Tables = 'SCHEMAS:Sales,HR,Production';
-- Grant permissions for specific tables
EXEC dbo.lakeflowFixPermissions
@User = 'myuser',
@Tables = 'Sales.Orders,HR.Employees';
Examples: Change tracking setup
Database-level only
-- Setup CT infrastructure without enabling on tables
EXEC dbo.lakeflowSetupChangeTracking
@Tables = NULL,
@User = 'myuser';
Enable on all tables
-- Enable CT on all user tables with primary keys
EXEC dbo.lakeflowSetupChangeTracking
@Tables = 'ALL',
@User = 'myuser';
Schema-based setup
-- Enable CT on all tables in specific schemas
EXEC dbo.lakeflowSetupChangeTracking
@Tables = 'SCHEMAS:Sales,HR',
@User = 'myuser',
@Retention = '3 DAYS';
Specific tables
-- Enable CT on specific tables
EXEC dbo.lakeflowSetupChangeTracking
@Tables = 'dbo.Table1,Sales.Orders,HR.Employees',
@User = 'myuser';
Create DDL support objects
-- Enable CT and create the DDL audit table and trigger for schema-change capture
EXEC dbo.lakeflowSetupChangeTracking
@Tables = 'ALL',
@User = 'myuser',
@CreateDdlSupportingObjects = 1;
Examples: CDC setup
Database-level only
-- Setup CDC infrastructure without enabling on tables
EXEC dbo.lakeflowSetupChangeDataCapture
@Tables = NULL,
@User = 'myuser';
Enable on all tables
-- Enable CDC on all user tables
EXEC dbo.lakeflowSetupChangeDataCapture
@Tables = 'ALL',
@User = 'myuser';
Specific tables
-- Enable CDC on specific tables
EXEC dbo.lakeflowSetupChangeDataCapture
@Tables = 'dbo.Table1,Sales.Orders',
@User = 'myuser';
Take ownership of pre-existing capture instances
-- Allow Lakeflow to disable pre-existing (non-Lakeflow) capture instances
-- during schema change handling
EXEC dbo.lakeflowSetupChangeDataCapture
@Tables = 'ALL',
@User = 'myuser',
@AllowDisablePreExistingCaptureInstances = 1;
Example: Hybrid approach
-- Step 1: Enable CT on tables with primary keys
EXEC dbo.lakeflowSetupChangeTracking
@Tables = 'ALL',
@User = 'myuser';
-- Step 2: Enable CDC on remaining tables (without primary keys)
EXEC dbo.lakeflowSetupChangeDataCapture
@Tables = 'ALL',
@User = 'myuser';
Example: Cleanup
-- Remove CT DDL support objects
EXEC dbo.lakeflowSetupChangeTracking
@Mode = 'CLEANUP';
-- Remove CDC DDL support objects
EXEC dbo.lakeflowSetupChangeDataCapture
@Mode = 'CLEANUP';
DDL support objects created
The following DDL support objects are created, depending on whether you use change tracking or CDC.
For change tracking
Object type | Name | Description |
|---|---|---|
Table |
| Stores DDL change history |
Trigger |
| Captures |
For CDC
Object type | Name | Description |
|---|---|---|
Table |
| Tracks capture instances |
Procedure |
| Removes old capture instance |
Procedure |
| Merges data between instances |
Procedure |
| Creates new capture instance |
Trigger |
| Handles schema changes |
Change tracking limitations
- Requires primary keys: Tables without primary keys cannot use change tracking.
- The script automatically skips tables without PKs and recommends using CDC instead.
Platform-specific behavior
- Azure SQL Database: System stored procedures are accessible by default (no
EXECUTEgrants needed). - Server-scoped views: Limited access in Azure SQL Database for views like
sys.change_tracking_databases.
Upgrade path
To upgrade, re-run the utility objects script, then re-run the setup procedures. The script recreates the utility functions and removes only legacy replicant-prefixed objects from earlier releases. It leaves your existing Lakeflow DDL support objects in place, so the current DDL trigger keeps capturing schema changes until you re-run the setup procedures. For instructions, see Step 1: Install or upgrade utility objects.
What happens during an upgrade:
- The utility functions and setup procedures defined by the script are dropped and recreated.
- Legacy
replicant-prefixed objects from earlier releases are removed. - Existing Lakeflow DDL support objects (
lakeflowDdlAudit_*,lakeflowDdlAuditTrigger_*,lakeflowCaptureInstanceInfo_*, and related procedures and triggers) are left in place. Re-running the setup procedures transitions them to the new version. The capture instance objects move whenever you re-runlakeflowSetupChangeDataCapture. The DDL audit table and trigger move only when you re-runlakeflowSetupChangeTrackingwith@CreateDdlSupportingObjects = 1, because they are opt-in. - Change tracking and CDC remain enabled on your tables. The upgrade does not disable them.
- CDC capture instances are not affected by the upgrade script.
After you run the upgrade script, re-run the setup procedures to recreate DDL support objects for the new version:
lakeflowSetupChangeTracking: with@CreateDdlSupportingObjects = 1, carries the DDL audit table and trigger forward tolakeflowDdlAudit_1_7. Pass this flag if your install uses DDL schema-change capture (it has alakeflowDdlAudittable), or the objects stay on the old version.lakeflowSetupChangeDataCapture: RecreateslakeflowCaptureInstanceInfo_1_7and the related procedures and trigger.
Both procedures are idempotent and safe to re-run with the original setup parameters.
To revert to a previous version of the utility objects script, contact Databricks Support.
Versioning scheme: objectName_majorVersion_minorVersion. Current objects use the _1_7 suffix.
Best practices
- Always run as
db_owneror a user with equivalent privileges. - Test on non-production databases first.
- Use the hybrid approach for comprehensive coverage.
- Run
lakeflowFixPermissionsafter setup to ensure proper user access. - Consider retention periods based on your ingestion frequency.
Troubleshooting
"User executing this script is not a 'db_owner' role member"
Solution: Execute as a user with db_owner role
"Change tracking is not enabled on catalog"
Solution: Enable CT at the database level or let the procedure handle it automatically
"Change data capture is not enabled on catalog"
Solution: Enable CDC at the database level or let the procedure handle it automatically
"Tables skipped due to missing primary keys"
Solution: Use lakeflowSetupChangeDataCapture for these tables instead
Validation integration
The following utility objects are validated by the Java validation framework:
Object | Description |
|---|---|
| Validates utility objects installation |
| Validates CT/CDC setup |
| Validates DDL support objects |
| Validates permissions |
Migration notes
If upgrading from older versions of DDL support objects (pre-utility objects era):
- The script automatically cleans up legacy objects.
- No manual cleanup is required.
- Version 1.1 consolidates all functionality into unified procedures.
Additional resources
- Prepare SQL Server for ingestion using the utility objects script
- Configure Microsoft SQL Server for ingestion into Databricks
- Microsoft SQL Server database user requirements
- Track data changes (SQL Server) in the SQL Server documentation
- About Change Tracking (SQL Server) in the SQL Server documentation
- What is change data capture (CDC)? in the SQL Server documentation