在 SQL Server 视图上触发或更改通知
我们有以下场景:
create table User {Id bigint, UserName nvarchar(50), GroupId bigint};
create table Group {Id bigint, GroupName nvarchar(50)};
create view UserView as
SELECT u.Id, u.UserName, g.GroupName
from User u
inner join Group g on u.GroupId = g.Id
现在我想在视图上创建一个触发器,如果更新用户表或/和更新组表,则会触发该触发器。
使用 T-SQL 可以实现这一点吗?
使用 INSTEAD OF 触发器不起作用,因为只有直接对视图执行更新时才会触发它们。
谢谢。
We have following scenario:
create table User {Id bigint, UserName nvarchar(50), GroupId bigint};
create table Group {Id bigint, GroupName nvarchar(50)};
create view UserView as
SELECT u.Id, u.UserName, g.GroupName
from User u
inner join Group g on u.GroupId = g.Id
Now I'd like to create one trigger on the view which is fired if the User table is updated or/and if the group table is updated.
Is this possible somehow using T-SQL?
Using INSTEAD OF triggers doesn't work because they are fired only if you perform updates directly to the view.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,这是不可能的。您必须在视图中涉及的表上定义触发器才能处理更改。
No, this is not possible. You'll have to define your triggers on the tables that are involved in the view in order to process changes.