Ok, I believe the question was not clear. Here i rewrite this in other way.
Suppose i create two tables,
table1(c1 int PRIMARY KEY)
table2(table1c11 int)
There is a relation between table1
and table2
i.e. table1.c1=table2.table1c11
And, i execute the following statement in the table1
and table2
insert into table1(c1)
values('a'),('b'),('c'),('d'),('e')
insert into table2(table1c11)
values('a'),('a'),('b'),('d')
And now what I want to achieve is that, once I update the value of c1
in table1
the corresponding data in table2
gets changed automatically. For this I need to create the constraint in table1
and table2
relationships and apply the CASCADE UPDATE
.
So, later I apply a new SQL update statement in table1
i.e.
Update table1 set c1=c1+'updated'
Then the data in table2
gets changed also, But what if I want to achieve the same functionality via INSTEAD OF UPDATE TRIGGER
, then I need to write the instead of update trigger and inside that, I need to handle that with two magic tables INSERTED
and DELETED
.
But the main point is that, in this case, I have only one column present in the table1
and I am updating that same column, so how could i map the inserted and deleted rows. Same thing is being done by the SQL Server as well if I use CASCADing.
So, the question arises how SQL Server handles batch update in case of the primary key data changes in the table.