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.1
- Major Version: 1
- Minor Version: 1
- Version Function:
lakeflowUtilityVersion_1_1()
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_1_1()
Detects the utility objects version.
Returns: '1.1'
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 DDL support.
Parameters:
Parameter | Description |
|---|---|
| Optional. Tables to enable CT on |
| Optional. User to grant permissions to |
| Optional. CT retention period (default: |
| Optional. |
@Tables parameter options:
Option | Description |
|---|---|
| Setup database-level CT and DDL support only (no table enablement) |
| 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
- Creates a versioned DDL audit table (
lakeflowDdlAudit_1_2) - Creates a DDL audit 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. |
@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_2) - Creates helper procedures for capture instance management:
lakeflowDisableOldCaptureInstance_1_2lakeflowMergeCaptureInstances_1_2lakeflowRefreshCaptureInstance_1_2
- 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 script
Download
lakeflow_utility_objects.sqlfrom [URL TO BE DETERMINED] -
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_1_1() 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 lakeflow_utility_objects.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';
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';
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
- The script automatically drops all previous versions when run.
- Versioning scheme:
objectName_majorVersion_minorVersion - Current objects use
_1_1suffix for version tracking.
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