Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
389 views
in Technique[技术] by (71.8m points)

Schedule a DML operation on EXTERNAL TABLEs in Azure SQL

I'm new to AzureSQL.
I want to migrate data from Azure SQL periodically based on timestamp.

use DB1 GO
delete DB2.dbo.Orders where OrderDate < GETDATE()-90

The database DB1 and DB2 are in the same server.
As I currently understand, there is no SQL Server Agent when using AzureSQL.

Thanks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  1. We can use exec sp_execute_remote to execute delete operation on EXTERNAL TABLEs.

  2. As you are running just one script, I think you can use Automation Account Runbooks. As an example below, a PowerShell Runbook to execute the statement.

    $database = @{
    'ServerInstance' = 'servername.database.windows.net'
    'Database' = 'databasename' 
    'Username' = 'uname'
    'Password' = 'password'
    'Query' = 'exec sp_execute_remote N''<Your-remote-datasource-name>'', N''delete DB2.dbo.Orders where OrderDate < GETDATE()-90''''   
    }
    Invoke -Sqlcmd @database

Then, it can be scheduled.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...