In my previous article, I explained how to implement Slowly Changing Dimension (SCD) Type 4 in Azure SQL Database. In this article, we will explore how to automate this process by creating an Azure SQL Database and executing the stored procedure using Azure Data Factory (ADF).
Creating an Azure SQL Database
- Navigate to Azure Portal: Go to portal.azure.com and open the marketplace.
![Azure Portal]()
- Search for Azure SQL Database and click Create.
- Provide Required Details.
- Select the appropriate Subscription and Resource Group (create a new one if needed).
- Provide a Database Name.
- If no existing server is available, create a new one.
![Database Name]()
Creating a New SQL Server
- Provide a Server Name and choose the Server Hosting Location.
- For authentication, select Microsoft Entra-only Authentication, as this is a best practice.
- Why not SQL Server Authentication? SQL Server Authentication relies on username/password combinations, which pose security risks such as credential leaks and brute-force attacks. Entra authentication enhances security through multi-factor authentication (MFA) and centralized identity management.
- Select the Entra Admin and click Create.
- When prompted for Elastic Pool, select No.
- What is an Elastic Pool? Elastic pools provide a cost-effective way to manage multiple databases with varying usage patterns by sharing resources among them.
- Leave the remaining settings as default and click Review & Create.
![Review & Create]()
Configuring Firewall Rules for SQL Server
- Navigate to: SQL Server > Security > Networking > Public Network Access.
- Select Selected Networks.
- Add your Client IPv4 Address and configure Virtual Network Rules if necessary.
- Enable "Allow Azure Services & Resources".
- Why enable this? This setting allows services like Azure Data Factory to communicate with the database without requiring additional firewall configurations.
![Azure Data Factory]()
Testing SQL Server Connectivity
- Open SQL Server Management Studio (SSMS).
- Click Connect > Database Engine.
- Enter the following details:
- Server Name: <server name>
- Authentication: Microsoft Entra MFA
- Username: <Entra Admin Username>
- Click Connect. Complete MFA authentication if prompted.
- The connection should be successful.
![SQL Server]()
![Object Explorer]()
Enabling System Assigned Managed Identity for Data Factory
To allow ADF to interact with the SQL Server securely, we will use System Assigned Managed Identity.
Step 1. Grant Data Factory Access to SQL Server.
- Ensure System Assigned Managed Identity is enabled for SQL Server under Security > Identity.
![Identity]()
Step 2. Assign Access to Data Factory.
- Navigate to Access Control (IAM).
- Select Role Assignments > Add Role Assignment.
- Under Assign Access To, choose Managed Identity.
- Search for ADF’s Managed Identity (using Identity ID/Name).
- Click Review & Assign.
![Click Review]()
Step 3. Configure Database Permissions.
While we have granted access to ADF at the server level, additional permissions are required for operations such as executing stored procedures, creating and dropping tables, and modifying database objects. To achieve this, we execute the following SQL commands.
- Create a user for the managed identity
- Grant read and write access
- Provide execution privileges for the stored procedure schema (Sproc)
- Allow creation, alteration, and dropping of database objects
CREATE USER [<managed-identity-name>] FROM EXTERNAL PROVIDER;
ALTER ROLE db_datareader ADD MEMBER [<managed-identity-name>];
ALTER ROLE db_datawriter ADD MEMBER [<managed-identity-name>];
GRANT EXECUTE ON SCHEMA::[Sproc] TO [<managed-identity-name>];
ALTER ROLE db_ddladmin ADD MEMBER [<managed-identity-name>];
These permissions ensure that ADF can execute stored procedures and perform necessary modifications to the database objects.
Creating a Linked Service in Azure Data Factory
A Linked Service establishes a connection between ADF and the database.
- Navigate to: Manage > Linked Services > New.
- Select Data Store: Choose Azure SQL Database.
- Provide Connection Details.
- Enter a Name for the linked service.
- Choose System Assigned Managed Identity as the Authentication Type.
- Note the Managed Identity Name & Object ID for access configuration.
- Click Test Connection and Save.
Types of Authentication in Linked Services
- SQL Authentication: Uses a username and password stored in ADF or Azure Key Vault. Suitable for legacy systems.
- Managed Identity: Uses Azure’s built-in identity system to authenticate securely without storing credentials. Best for Azure services.
- Service Principal: Authenticates using an Azure AD service principal (client ID & secret/certificate). Ideal for automated access.
![Azure AD service]()
![Linked]()
Creating a Pipeline to Execute the Stored Procedure
- Navigate to the Author Tab (Pencil Icon).
- Click + (Create New Pipeline).
- Drag and drop the Stored Procedure Activity onto the canvas.
- In the Settings Tab.
- Select the Linked Service created earlier.
- Choose or manually enter the Stored Procedure Name.
- If the procedure has parameters, click Import and provide values. While executing the pipeline, this value will be passed as an argument to the stored procedure. In my stored procedure, there are no parameters, so nothing was imported.
![Stored Procedure Name]()
![Settings]()
Adding a Lookup Activity to Validate Data
- Drag and drop Lookup Activity onto the canvas.
- In Settings.
- Click create dataset if not created. A dataset in ADF stores metadata about a data source and allows activities such as Lookup to retrieve data.
- Select the Linked Service and the corresponding Table.
- Enable First Row Only.
- Provide a SQL Query to fetch row count.
![SQL Query]()
![Publish All]()
Scheduling Pipeline Execution
- Go to Manage > Triggers > New.
- Select a Trigger Type
- Schedule: Runs at specific intervals.
- Tumbling Window: Processes data in batches.
- Event-based: Executes when a file is uploaded.
- Configure recurrence and click OK.
- Click Publish All to save changes (as there's no Save option without Git Integration).
![Publish]()
Testing the Pipeline Execution
- Click Debug to validate the pipeline (this executes all configured actions).
- Delete a few rows from the staging table and re-execute the pipeline.
![Debug]()
![Pipeline]()
- Monitor execution under Monitor > Pipelines.
![Monitor]()
- Verify data changes in Dimension & History Tables.
![History Tables]()
Conclusion
In this article, we successfully.
- Created an Azure SQL Database.
- Configured firewall rules and tested connectivity.
- Enabled Managed Identity authentication for ADF.
- Created a Linked Service for ADF to connect to the database.
- Scheduled a pipeline to automate stored procedure execution.
For more details on setting up a storage account and creating datafactory and moving files using ADF, refer to my previous article: Create Storage Account & Move Files Using ADF.