Trigger not executing when a Batch Update runs - vb.net

I am using VB.Net 2008 and ADO.Net to do a Batch Update to our Oracle database.
The updates are working, but there is a trigger on the table before the row is updated to enforce a member's termination termination date.
So if I was trying to set the termination date (via the batch update) to 31-Jan-2010 but the member had a claim that was processed on 2-Feb-2010 the trigger would force the termination date to be 2-Feb-2010. However, the trigger is NOT executing when the batch update runs?
Is there any Oracle DB Admin option that would disable Triggers on Batch Update?

A direct path load through SQL*Loader can disable and reenable triggers as described here
What does the batch update do. Maybe if it does a DELETE+INSERT, rather than an UPDATE, then the trigger won't fire.

The alter trigger command can be used to disable a trigger,
ALTER TRIGGER trigger_name DISABLE
This will show the enabled/disabled status of all triggers,
select trigger_name, status from user_triggers

Related

Is it Possible to Disable the Triggers in the SQL Server 2012 for the Particular Stored Procedure Run While it will be active in the other Processes?

Is it possible to disable the triggers for a particular stored procedure run while it will be active in the other processes?
Like if
update Table A
having Update Trigger TrA with a SP
Trigger will not work but if I do the update manually will the trigger work?
Any property for the SP.

Oracle: Stop trigger for some time

I have created a trigger and I want to stop the trigger from executing its code for some time. Is there any function available in oracle for this.
Being more specific:-
I have to perform an action when a PO is created in oracle apps.
I need to find requisition number for this po which I will get by joining distributions and lines table. But when trigger is fired there wont be any data in lines and distribution table.
alter trigger <trigger_name> disable;
then to enable
alter trigger <trigger_name> enable;
You cannot delay your trigger, it will fire as soon as you perform the event on the table.
There is no native database way to delay the trigger for some specified period of time.
In general you can enable or disable trigger using,
ALTER TRIGGER trigger_name ENABLE/DISABLE;
You can write this code in a stored procedure and then get it executed using some out-of-the-database program, e.g. PHP, JAVA, SHELL etc. (depending on your architecture) that supports time driven execution
DBMS_LOCK.SLEEP might to the trick:
http://docs.oracle.com/cd/E11882_01/appdev.112/e40758/d_lock.htm#ARPLS66781
You can easily delay an action by creating a job.
For example, your trigger may call DBMS_JOB.submit to create a job to run at a particular time (e.g. 10 minutes after the current time). The job needs to be created with the name of a procedure that needs to be run. For example, you might create a procedure that takes a record ID as a parameter.
The nice thing about DBMS_JOB is that it is transactional - so if your triggering statement is rolled back, the job will also be rolled back.
The downside is that the job will never start until after the statement that created it is committed.

SQL Server disable trigger timeout

I have table with update cursor which do not allow me to do bulk updates on it, but need to do some periodical bulk updates (query in sql job). To do this I want to disable cursor in code (disabling trigger in SSMS can ends with timeout error), but when disabling in query runs until I stop it.
Can I somehow set timeout for disabling trigger in query code (or set timeout for job run)?
Thanks
Another option might be to use CONTEXT_INFO. This allows you to set a sort of global variable that is scoped to the current request. Before executing the bulk update you can set the CONTEXT_INFO to a specific value. The trigger can check for this value and skip execution. This way you don't have to disable the trigger.
You could make disabling and re-enabling the trigger part of the transaction. Then if the update query times out, the disabling of the trigger will be rolled back too.

TSQL - Disabling Triggers in Transactions

I've search high and low, and I haven't been able to find a satisfactory answer to my question. Which tends to boil down to how exactly a TRANSACTION works in SQL Server.
Basically, will this do what I think it does.
BEGIN TRAN
DISABLE [my_update_trigger] ON [my_table]
/*.. Do Some Updates ..*/
ENABLE [my_update_trigger] ON [my_table]
COMMIT TRAN
I want to be able to fix some data in a table, without running the update triggers
I have on the table. This is for a web app, so I'd like to make sure that if an update is done on the table from the web app, while I'm doing my work, [my_update_trigger] will still fire for the web app.
The update stuff is ok - the disable enable etc.
DISABLE TRIGGER [my_update_trigger] ON [my_table]
/*.. Do Some Updates ..*/
ENABLE TRIGGER [my_update_trigger] ON [my_table]
Have a look at the msdn page: http://msdn.microsoft.com/en-us/library/ms189748.aspx
On making it session specific though: I'd doubt if that would work - the disable/enabled are DDL rather than DML, ie they act on the database objects rather than the data. I wouldn't have thought this would be in the scope of a Transaction
Semicolons work for me:
BEGIN TRAN
;DISABLE [my_update_trigger] ON [my_table]
/*.. Do Some Updates ..*/
;ENABLE [my_update_trigger] ON [my_table]
COMMIT TRAN
I did some tests and, apparently, your code does exactly what you want it to do. Here is my test protocol:
-- Session 1 -- -- Session 2 --
1. BEGIN TRANSACTION
2. DISABLE TRIGGER [my_update_trigger] ON [my_table]
3. UPDATE my_table SET x = y -- blocks
4. ROLLBACK
-- unblocks *and triggers the trigger*
In addition, SELECT is_disabled FROM sys.triggers where name = 'my_update_trigger'; reveals that the trigger is disabled after step 2 and enabled after step 4.
Thus, my conclusion is:
Yes, enabling/disabling triggers is "global" and not "per session" (as can be seen by querying sys.triggers), but
SQL Server's locking mechanisms ensure that disabling a trigger in a transaction locks the table, so other sessions won't "miss" their trigger.
A word of caution: DISABLE TRIGGER won't trigger an implicit transaction. This is important if you are using (classic) ADO, since Connection.BeginTrans won't start an explicit transaction but will rather SET IMPLICIT_TRANSACTION ON. You need to perform one of the operations listed here before disabling the trigger, or the DISABLE TRIGGER statement will be outside the transaction.
if you want to execute ENABLE TRIGGER Directly From Source :
we can't write :
Conn.Execute "ENABLE TRIGGER trigger_name ON table_name"
instead, we can write :
Conn.Execute "ALTER TABLE table_name DISABLE TRIGGER trigger_name"

prevent updates, deletes and truncates on database table

I am in the process of creating a sql server 2008 database table for auditing users actions.
Is it possible to create a database table which can only inserted in to - no truncates, deletes or updates allowed on the data in the table. One option I know of is to use a different user with limited rights, but this isnt option for me. So looking at other options?
You need to create a TRIGGER that fires on UPDATE and DELETE and throws an error:
CREATE TRIGGER user_action_update on UserActions FOR UPDATE, DELETE AS
BEGIN
RAISERROR ('Cannot modify or delete user actions', 16, 1)
ROLLBACK TRAN
RETURN
END
GO
Source: http://msdn.microsoft.com/en-us/magazine/cc164047.aspx
Another way to do that is to Write a trigger creation script for the table and set the action to " INSTEAD OF " which will override the triggering action (unwanted action in your case ) for some other code, or null code.
INSTEAD OF Property
Specifies that the DML trigger is executed instead of the triggering SQL statement, therefore, overriding the actions of the triggering statements.
Here is a link in how to Write the SQL statement for the trigger creation:
http://technet.microsoft.com/en-us/library/ms189799.aspx
Good luck
Adrian