table tbl A (around 10M rows)
{
id (unique clustered index on it)
col1,
col2,
col3,
col4,
col5
)
table restrictTblA (around 50k rows)
{
id (unique clustered index on it)
}
To define a trigger (for update) on tblA to prevent col1 and col3 be updated for those ids in restrictTblA.
I am doing something like
if exists (
select 1
from
inserted a,
deleted b
where
a.id = b.id and
exists ( select 1 from restritTblA where id = a.id ) and
(
a.col1 != b.col1 or
a.col3 != b.col3
)
)
then
raiserror xxxxxx, "xxxxxxxxxxxxxxxxxxxx"
rollback transaction
return
end
I tested it using a update statment for 1000 rows without change on col1 and col3, the trigger takes 20 seconds!!!! I mimic the same sql above (just replace the logic tables inserted and deleted with two temp tables) and run manully, the if check just takes 1 second, is the join on inserted and deleted so expensive? anyway to tune it?
{
id (unique clustered index on it)
col1,
col2,
col3,
col4,
col5
)
table restrictTblA (around 50k rows)
{
id (unique clustered index on it)
}
To define a trigger (for update) on tblA to prevent col1 and col3 be updated for those ids in restrictTblA.
I am doing something like
if exists (
select 1
from
inserted a,
deleted b
where
a.id = b.id and
exists ( select 1 from restritTblA where id = a.id ) and
(
a.col1 != b.col1 or
a.col3 != b.col3
)
)
then
raiserror xxxxxx, "xxxxxxxxxxxxxxxxxxxx"
rollback transaction
return
end
I tested it using a update statment for 1000 rows without change on col1 and col3, the trigger takes 20 seconds!!!! I mimic the same sql above (just replace the logic tables inserted and deleted with two temp tables) and run manully, the if check just takes 1 second, is the join on inserted and deleted so expensive? anyway to tune it?