Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you `UPDATE` an SQL Server table without triggering the UPDATE trigger

I have an update trigger that updates some important status fields in a table tblCurrent.
When I first upload the daily batch of records into tblCurrent (circa 10K records), I perform some UPDATEs via three separate stored procedures when these are first uploaded and only then. How can I prevent the update trigger from running during these three initial UPDATEs?

like image 551
aSystemOverload Avatar asked Sep 24 '13 07:09

aSystemOverload


People also ask

What is instead of UPDATE trigger?

An INSTEAD OF trigger is an SQL trigger that is processed “instead of” an SQL UPDATE, DELETE or INSERT statement. Unlike SQL BEFORE and AFTER triggers, an INSTEAD OF trigger can be defined only on a view, not a table.

Can we UPDATE table without WHERE clause?

Without using any WHERE clause, the SQL UPDATE command can change all the records for the specific columns of the table.

Does UPDATE trigger fire on DELETE?

A DELETE does not fire UPDATE triggers. If you have a trigger defined to be fired on DELETE and also on UPDATE then it will be executed on a DELETE but that's because it's also a DELETE trigger.


1 Answers

You could temporary disable triggers for the table and then enable them back. MSDN article.

DISABLE TRIGGER { [ schema_name . ] trigger_name [ ,...n ] | ALL } ON { object_name | DATABASE | ALL SERVER } [ ; ]

ENABLE TRIGGER { [ schema_name . ] trigger_name [ ,...n ] | ALL } ON { object_name | DATABASE | ALL SERVER } [ ; ]

For example to disable all triggers for given table run following statement:

DISABLE TRIGGER ALL ON tblCurrent;
like image 128
Ivan Korneliuk Avatar answered Oct 04 '22 02:10

Ivan Korneliuk