触发视图 [英] Triggers on views

查看:73
本文介绍了触发视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以在sql server的视图上编写触发器吗?如果是,何时将触发这些触发器?
假设我在视图上写了一个插入触发器,当我将数据插入到构建视图的基表中时会触发吗?

Can we write triggers on view in sql server. If yes when will these triggers get fired? Suppose i write an insert trigger on the view, will it fire when i insert data into the base table from which the view has been built?

推荐答案

是的,您可以在视图上创建触发器。 (因为至少 SQL Server 2000 )。

Yes, you can create triggers on views. (Since at least SQL Server 2000.)

如果在视图上创建触发器,则不会在插入基表时触发。如果您希望在将数据插入基表中时发生某些事情,请在基表上创建触发器。

If you create a trigger on a view, it won't fire on inserts to the base table. If you want something to happen when you insert data into a base table, create a trigger on the base table.

您可以在视图上创建INSTEAD OF触发器,并使该触发器将数据插入基表中。

You can create an INSTEAD OF trigger on a view, and have that trigger insert data into a base table.

在您自己的模式中进行测试有多难?

How hard is it to test that in your own schema?

这篇关于触发视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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