Avoid beginners to update production table is the better way to avoid disaster!
In the author concept thers's a BIG BUG!
If before the trigger as described in the article another trigger is called the @@rowcount may be modified and the check will fail.
Remember: @@ROWCOUNT is countinuosly modified from SELECT, UPDATE, INSERT, DELETE.
When you create the trigger as in the article, you should be sure that your trigger is called first.
SET @Count = @@ROWCOUNT; -- Are you sure that this trigger is called first? Another one may modify @@rowcount
IF @Count >= (SELECT SUM(row_count)
FROM sys.dm_db_partition_stats
WHERE OBJECT_ID = OBJECT_ID('table')
)
Here a simple example of the BUG.
create table tmptmp(a sysname primary key)
insert tmptmp select name from sys.objects
go
create trigger tr_tmptmp on tmptmp
for update
as
begin
select 1 -- modify @@rowcount
print @@rowcount
end
go
create trigger tr_tmptmp_1 on tmptmp
for update
as
begin
print @@rowcount
end
go
update tmptmp set a = a