SQL触发器可以调用Web服务吗? [英] Can a SQL trigger call a web service?

查看:228
本文介绍了SQL触发器可以调用Web服务吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iPhone应用程序构建RESTful API。

I'm building out a RESTful API for an iPhone app.

当用户签入 [将新行插入表中]我想然后从该插入中获取数据并调用Web服务,该服务将基于该插入发送推送通知。

When a user "checks-in" [Inserts new row into a table] I want to then take data from that insert and call a web service, which would send push notifications based upon that insert.

我唯一想到的方法就是要么这样做通过触发或具有实际的插入方法,成功插入后,将调用Web服务。对我来说,这似乎是个坏主意。

The only way I can think of doing this is either doing it through a trigger, or having the actual insert method, upon successful insert, call the web service. That seems like a bad idea to me.

想知道您是否对此有任何想法,或者是否有我没有想到的更好的方法。

Was wondering if you had any thoughts on this or if there was a better approach that I haven't thought of.

推荐答案

即使从技术上讲,它也不是一个好主意!触发器应该非常精简,并且绝对不应该涉及冗长的操作(Webservice调用肯定是这样)!重新考虑您的体系结构-应该有一个更好的方法来做到这一点!

Even if it technically could, it's really not a good idea! A trigger should be very lean, and it should definitely not involve a lengthy operation (which a webservice call definitely is)! Rethink your architecture - there should be a better way to do this!

我的建议是将注意任务分开,以调用Web服务,

My recommendation would be to separate the task of "noticing" that you need to call the webservice, in your trigger, from the actual execution of that web service call.

类似这样的事情:


  1. 在触发代码中,在表中插入稍后再调用Web服务(只需 INSERT 即可保持精简和快速-如此)

  1. in your trigger code, insert a "do call the webservice later" into a table (just the INSERT to keep it lean and fast - that's all)

具有异步服务(SQL作业,或者最好是Windows NT Service),该服务与实际触发器执行分开进行那些调用,并存储从中获取的所有数据将该Web服务放入数据库中的相应表中。

have an asynchronous service (a SQL job, or preferably a Windows NT Service) that makes those calls separately from the actual trigger execution and stores any data retrieved from that web service into the appropriate tables in your database.

触发器是一件非常挑剔的事情-应该始终是非常快,非常精简-最多执行 INSERT 或两个-并尽量避免在触发器或其他冗长的操作(如Web服务调用)中使用光标

A trigger is a very finicky thing - it should always be very quick, very lean - do an INSERT or two at most - and by all means avoid cursors in triggers, or other lengthy operations (like a web service call)

Brent Ozar在无法扩展的十大开发人员错误和触发器是他关注的第一件事!强烈推荐

Brent Ozar has a great webcast (presented at SQL PASS) on The Top 10 Developer Mistakes That Don't Scale and triggers are the first thing he puts his focus on! Highly recommended

这篇关于SQL触发器可以调用Web服务吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆