Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger or Change Notification on SQL Server view

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.

like image 629
Bernhard Avatar asked Jul 01 '26 21:07

Bernhard


1 Answers

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.

like image 170
Adam Robinson Avatar answered Jul 05 '26 11:07

Adam Robinson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!