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

查看:22
本文介绍了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.

我能想到的唯一方法是通过 trigger 执行此操作,或者使用实际的插入方法,在成功插入后调用 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.

推荐答案

即使技术上可以,也确实不是一个好主意!触发器应该非常精简,绝对不应该涉及冗长的操作(Web 服务调用肯定是这样)!重新思考您的架构 - 应该有更好的方法来做到这一点!

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 服务的任务与该 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. 在您的触发器代码中,将稍后调用网络服务"插入表中(只需 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 服务),它使这些调用与实际的触发器执行分开,并将从该 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 - 并且一定要避免触发器中的游标或其他冗长的操作(就像一个网络服务调用)

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 在 不可扩展的 10 大开发者错误和触发器是他首先关注的事情!强烈推荐

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天全站免登陆