简体   繁体   English

如何每天在Azure数据库上运行T-SQL查询

[英]How to run a T-SQL query daily on an Azure database

I am trying to migrate a database from a sql server into Azure. 我正在尝试将数据库从sql服务器迁移到Azure。 This database have 2 rather simple TSQL script that inserts data. 该数据库具有2个相当简单的插入数据的TSQL脚本。 Since the SQL Agent does not exist on Azure, I am trying to find an alternative. 由于SQL代理在Azure上不存在,因此我试图找到一种替代方法。

I see the Automation thing, but it seems really complex for something as simple as running SQL scripts. 我看到了自动化的东西,但是对于像运行SQL脚本这样简单的东西来说似乎真的很复杂。 Is there any better or at least easier way to do this ? 有没有更好或更简单的方法可以做到这一点?

I was under the impression that there was a scheduller for that for I can't find it. 我的印象是有一个调度程序,因为我找不到它。

Thanks 谢谢

You can use Azure Functions to Run the T-SQL Queries for Schedule use Timely Trigger . 您可以使用Azure函数运行T-SQL查询以进行计划使用“ 及时触发”

在此处输入图片说明

There are several ways to run a scheduled Task/job on the azure sql database for your use case - 对于您的用例,有几种方法可以在Azure SQL数据库上运行预定的任务/作业-

  1. If you are comfortable using the existing on-premise sql sever agent you can connect to your azure sql db(using linked servers) and execute jobs the same way we used to on on-premise sql server. 如果您对使用现有的本地sql服务器代理感到满意,则可以连接到Azure sql数据库(使用链接的服务器)并以与本地sql服务器相同的方式执行作业。

  2. Use Automation Account/Runbooks to create sql jobs. 使用自动化帐户/运行簿创建sql作业。 If you see marketplace you can find several examples on azure sql db(backup,restore,indexing jobs..). 如果您看到市场,则可以在azure sql db上找到几个示例(备份,还原,索引作业..)。 I guess you already tried it and does not seem a feasible solution to you. 我想您已经尝试过了,对您来说似乎不是可行的解决方案。

  3. Another not very famous way could be to use the webjobs(under app service web app) to schedule tasks(can use powershell scripts here). 另一种不是很出名的方法可能是使用webjobs(在应用程序服务Web应用程序下)安排任务(可以在此处使用Powershell脚本)。 The disadvantage of this is you cannot change anything once you create a webjob 这样做的缺点是一旦创建了Webjob,您将无法更改任何内容

  4. As @jayendran suggested Azure functions is definitely an option to achieve this use case. 正如@jayendran所建议的,Azure功能绝对是实现此用例的一种选择。

  5. If some how out of these if you do not have options to work with the sql directly , there is also "Scheduler Job Collection" available in azure to schedule invocation of HTTP endpoints, and the sql operation could be abstracted/implemented in that endpoint. 如果您没有直接使用sql的选项,如果还有一些其他方法,还有一些“ Scheduler Job Collection”可用于安排HTTP端点的调用,并且可以在该端点中抽象/实现sql操作。 This would be only useful for less heavy sql operations else if the operation takes longer chances are it might time out. 这仅对不太繁重的sql操作有用,否则,如果该操作可能会超时,则机会较长。

You can use Microsoft Flow ( https://flow.microsoft.com ) in order to create a programmed flow with an SQL Server connector. 您可以使用Microsoft Flow( https://flow.microsoft.com )来创建带有SQL Server连接器的编程流。 Then in the connector you set the SQL Azure server, database name, username and password. 然后在连接器中设置SQL Azure服务器,数据库名称,用户名和密码。

SQL Server connector SQL Server连接器

There are many options but the ones that you can use to run a T-SQL query daily are these: 有很多选项,但是您可以每天用来运行T-SQL查询的选项有:

SQL Connector options SQL连接器选项

  • Execute a SQL Query 执行SQL查询
  • Execute stored procedure 执行存储过程

You can also edit your connection info in Data --> Connections menu. 您也可以在数据->连接菜单中编辑连接信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM