How to schedule procedure in Azure Synapse - azure-synapse

I have some procedures created in Azure DWH and need to schedule to procedures daily.
Earlier we used to run them using SQL Agent but looks like thats not possible in Synapse

Unfortunately, Azure Synapse Analytics doesn't support scheduling stored procedures.
Stored procs were recently released on the serverless SQL pool engine side. Synapse Studio support yet to come.
Refer: Using stored procedures in Synapse SQL pool

This scenario is possible by using Synapse Pipelines inside Azure Synapse Studio.
Open your Azure Synapse Analytics workspace
Go to Integrate activity hub
Create new Pipeline
Drag & Drop activity called: "SQL Pool Stored Procedure"
Select SQL dedicated pool where you would like to execute store procedure
Select store procedure which you would like to execute
Trigger the pipeline by clicking "Add trigger" and then Trigger now (for example)
In the Monitor activity hub you can see the results of that pipeline and stored procedure inside.
If you are having Dedicated pool (formerly known as SQL DW gen2) then you can upgrade it to Workspace lite and then follow same steps as for standard workspace above.

If you would like to schedule queries using the serverless approach on Synapse you need to use the stored procedure activity in the ADF pipeline.
Steps followed (with useful resources):
Create the serverless SQL database and connect it to your external storage (https://learn.microsoft.com/en-us/azure/synapse-analytics/get-started-create-workspace)
Create and test a SQL query on the db
Create a stored procedure from the SQL query and save it to the db. (https://endjin.com/blog/2021/08/managing-schemas-in-azure-synapse-sql-serverless)
Create a ADF pipeline and select a stored procedure activity.
Create a linked service, where you link the serverless db endpoint. This endpoint can be found in the Azure Portal under the Synapse workspace. You will need to make sure of permissions on the db to enable connection.
In the stored procedure activity, link to the created linked service. The stored procedure should then be selectable.
Merge the feature branch to the main branch and publish.
Create a trigger and link it to the published pipeline.

Related

Can we use SQL scripts (Develop hub) during pipeline creation (Integrate hub) in azure synapse?

I want to use my SQL script (present under Develop hub) file inside a Pipeline (present under Integrate hub). Currently I do not see any Activities available solving this purpose.
There is one Script activity under General section which only have a Query & NonQuery option, not for referring any SQL script file created earlier.
Is that feature available at all in Azure Synapse Analytics? Can we refer to SQL script by some other means?
If your Synapse workspace is paired with Azure DevOps then I imagine it’s easy to get the file content with a REST API call (eg here). However then you have to parse the file as GO is not supported by the Script activity. ADF / Synapse Pipeline functions do not support a RegEx style split eg word boundary and GO (\bGO\b) so it starts to get kind of fiddly. I had some success with replace and uriComponent functions.
However you would be better of using Stored Procedures and the Stored Proc activity in Synapse Pipelines - much simpler implementation.

How to set up recurring migration through queries/script from SQL server(On-premise) to Azure SQL database

I need a help to sync the data on Azure SQL from SQL server(On-premise).
Available recourses:
2 Database (SQL Server) on premise available on different server
Azure SQL database on cloud
Migration script/queries are ready to fetch data from on-premise sql server
Requirements:
Set up a scheduler which will run every 12 hours means two times in a day on Azure SQL.
In scheduler, using migration scripts data will be fetch from the On-premise SQL server and insert into Azure SQL Database.
One of the most prevalent Azure SQL DB migration/replication features is Azure Data Sync.
There are two sorts of schedules: Automatic and Manual. Automatic schedules function on time intervals, with the lowest number being 5 minutes. The second kind is the manual schedule, which allows the user to conduct the sync anytime they want using the Azure Portal or PowerShell. The goal of this PowerShell workflow script is to do a one-time sync manually, then switch to automatic sync and configure Sync time intervals according to your preferences.
you can refer this links to setup data sync Set up Data Sync in the Azure portal, Set up Data Sync with PowerShell
Reference: Schedule Data Sync with Azure SQL Database use an Automation account

how to schedule a query in Azure synapse on-demand

how to schedule a Query in Azure Synapse On-demand and save the result to a azure storage every 1 hour
my idea is to materialize the results into a separate storage and use PowerBI to access the results
Besides the fact that PowerBI can directly access your Synapse instance, if you want to go this route you have several options:
This can be done using a pipeline in the new Synapse Workspace. You should be aware that this technology is still in preview.
Use Polybase and Stored Procedures on a Job Scheduler to INSERT to a Blob Storage location. There is a lot of configuration in this option.
At present, I would recommend Azure Data Factory (ADF) on a Schedule Trigger. This is the simplest and most reliable of the current options. Based on the scenario you described, a single Copy activity could easily perform this task.

Options for ingesting and processing data in Azure sql

I need expert opinion on a project I am working on. We currently get data files that we load into our Azure sql database using a local script that calls stored procedures. I am planning on replacing the script with ssis jobs to load the data into our Azure Sql but wondering if that's a good option given our needs.I am opened to different suggestions too. The process we go through is to load data file to staging tables and validate before making updates to live tables. The validation and updates are done by calling stored procedures...so the ssis package will just load the data and make calls to those stored procedures. I have looked at ADF IR and Databricks but they seem overkill but am open to hear people with experience using those as well. I am currently running the ssis package locally as well. Any suggestion on better architecture or tools for this scenario? Thanks!
I would definitely have a look at Azure Data Factory Data flows. With this you can easily build your ETL pipelines in the a Azure Data Factory GUI.
In the following example two text files from a Blob Storage are read, joined, a surrogate key is added and finally the data is loaded to Azure Synapse Analytics (would be the same for Azure SQL):
You finally put this Mapping Data Flow into a pipeline and can trigger it, e. g. if new data arrives.
You can just BULK INSERT data from Azure Blob Store:
https://learn.microsoft.com/en-us/sql/relational-databases/import-export/examples-of-bulk-access-to-data-in-azure-blob-storage?view=sql-server-ver15#accessing-data-in-a-csv-file-referencing-an-azure-blob-storage-location
Then you can use ADF (no IR) or Databricks or Azure Batch or Azure Elastic Jobs to schedule the execution.

Migrate SQL Server database to Azure along with database email and jobs

I am new to SQL Azure, we have taken the subscription of Azure SQL elastic pool.
I have two databases in my local SQL Server and it has a stored procedure which internally is calling msdb.dbo.sp_send_dbmail and I have scheduled these stored procedures to run in a job (SQL Server Agent -> Scheduler).
I want to move these two databases along with DB-mail accounts and SQL Server jobs to Azure. I am finding difficulties as in my subscription I am not able to see msdb, SQL Server Agent and database email. We want to go with only SQL Azure as service, no need your support on these.
I tried to deploy the database and getting the error message:
Error
SQL71562: Error validating element [dbo].[AMPLoanAgingEMail]:
Procedure: [dbo].[AMPLoanAgingEMail] has an unresolved reference to object [msdb].[dbo].[sp_send_dbmail].[#profile_name]. External references are not supported when creating a package from this platform.
The expected result is I want to move those scheduled jobs and stored procedures to my Azure.
Azure SQL database doesn't support msdb database. We can not migrate msdb to Azure or do anything with it in Azure SQL database.
For more details, please see: msdb database.
SQL server agent is only supported Azure SQL Managed Instance only.
Database email also is not supported in Azure SQL Database.
This why you can not be able to see msdb , SQL server agent and database email.
Your stored procedure [dbo].[AMPLoanAgingEMail] could not call the [msdb].[dbo].[sp_send_dbmail] in msdb. The error message also mentioned that.
For now, there isn't a solution for msdb in Azrue SQL Database.
Before migrate your database to Azure SQL database, you can use Data Migration Assistant(DMA) to help you assess your database.
Hope this helps.