SQL Server 2012 :: Disable Only One Trigger Action?

May 6, 2014

I have a trigger that executes AFTER INSERT, UPDATE, DELETE. Is there a way to disable and then reenable only the "AFTER DELETE", letting AFTER INSERT, UPDATE act normally?

View 6 Replies


ADVERTISEMENT

SQL Server 2012 :: Trigger For Update Action Without Primary Key

Jun 18, 2015

I am writing a trigger for getting values to auditlog table when the values gets updated. Below is the code of my trigger.

CREATE TRIGGER [dbo].[Update_Temp] ON [dbo].[Temptable1] FOR UPDATE
AS
DECLARE @bit INT ,
@field INT ,
@maxfield INT ,
@char INT ,
@fieldname VARCHAR(128) ,
@TableName VARCHAR(128) ,

[Code] ....

The code is working fine when the table has primary key associated. However due to some restrictions I will not be able to have a primary key for some tables. I want to implement the same trigger in those tables too. When there is primary key, that primary key needs to get inserted into the audit table and if there is no primary key, i want a specific column value to get inserted instead of the primary key value into the audit table.

For example, i have a student table in which there is a student id, name, dob. there is no primary key defined for the table. So when i update the name or dob, i need the student id to get inserted into the Pk column of the audit table.

I tried modifying the code by checking the @pkcols for Null and if its null to get the old value as the primary key however I was not able to do it .

View 1 Replies View Related

SQL 2012 :: Disable And Enable Trigger?

May 25, 2015

I have a trigger that I disable so I can do some operations on a table.

After the operations are completed I do the enable using the enable trigger comand.

Do I need to do something else to put back the trigger working as it was before the disable comand?

View 3 Replies View Related

SQL 2012 :: SSDT Database Project - Cross DB Trigger Enable / Disable Gives Warning 71502

Jul 13, 2015

I have 2 dbs (SQL 2012) - one contains a trigger that is enabled/disabled by a procedure in the other database. This all works fine.

If I create a Database Project solution in Visual Studio 2012 SSDT (or 2013) for both databases, the stored procedure generates a SQL71502 stating that my trigger name can't be resolved.

To recreate the issue:

CREATE DATABASE DbWithTrigger
GO
USE DbWithTrigger
GO
CREATE TABLE dbo.TblWithTrigger(
Id int NULL,
SomeValue varchar(30) NULL

[code]....

-- Test to confirm

EXEC CrossDbTriggerCall
INSERT DbWithTrigger.dbo.TblWithTrigger VALUES(1, 'Blah blah')

In Visual Studio 2012:

1. Create a new solution with a project named DbWithTrigger
2. In project settings set the Target platform to SQL 2012
2. Import the DbWithTrigger db into this project
3. Create a new project named DbCallsTrigger
4. In project settings set the Target platform to SQL 2012
5. Import the DbCallsTrigger db into this project
6. Add a Database Reference in DbCallsTrigger for DbWithTrigger

When you build the solution both dbs build successfully, however there are two warnings. One is easily resolved by replacing DbWithTrigger in the body of the procedure with [$(DbWithTrigger)] (db variable name for the reference) but I can't find out how to get rid of the other. Is it a bug?

View 1 Replies View Related

SQL Server 2012 :: Create Row Number For A Consecutive Action

Nov 26, 2013

How to create a row number for a consecutive action. Example: I have a listing of people who have either completed a goal or not. I need to count by person the number of consecutively missed goals.

My sql table is this:
PersonId, GoalDate, GoalStatus (holds completed or missed)

My first thought was to use the rownumber function however that doesn’t work because someone could complete a goal, miss a goal, then complete one and when they complete a goal after a missed goal the count has to start over.

View 9 Replies View Related

SQL Server 2008 :: Enable And Disable Trigger

Oct 25, 2015

the disable trigger will be enable again.Because I already disable the trigger on last month, but when I check through the database, it enable again.I understand that, when we restore the database, all the trigger will be enable.How about SQL Cluster? will it enable the trigger??

View 3 Replies View Related

Is Multiple Action Trigger Possible

Apr 8, 2007

Hello
Is it possible to create a trigger with multiple actions?
I would like to create a trigger with INSERT, DELETE, UPDATE funtions but I have not been above to find a clear syntax example
Below I have created a statement of my trigger.  Could somebody please confirm if the syntac in this multiple action trigger is ok.multple actions on a single trigger
Is this syntax correct?
CREATE TRIGGER [dbo].[trig_AddDomCatA] ON DomainNames For INSERT, DELETE, UPDATE
AS
INSERT INTO Domain_CatA (DomainName)SELECT DomainName FROM INSERTED
ASDELETE FROM Domain_CatA (DomainName)SELECT DomainName FROM DELETED
ASUPDATE INTO Domain_CatA (DomainName)SELECT DomainName FROM UPDATED
 Thanks
Lynn
 
 
 

View 7 Replies View Related

How Do I Know What Action Triggered A Trigger...

Aug 2, 2004

Hello

If I have a trigger for INSERT and DELETE, how do I know what action was executed ??
I prefer not to split the trigger to one for each action, because the the procedure for both is almost the same.

Another question, How can I know what records were updated? I need to concatenate the ID/ID's to the SQL in the procedure.

Thanks,

Inon.

View 2 Replies View Related

TRIGGER Action For Eace Row

Sep 21, 2007

I need to define a TRIGGER on a table (temp1) that executes the triggered action for each row of the subject table(temp1) that the triggering SQL modifies. If the triggering SQL operation does not modify any rows, the triggered action is not executed.E.g., If SQL modifies 100 rows, trigger executes 100 times. How can i achieve this type of Trigger in SQL Server .In DB2 i can acheive this by specifying 'FOR EACH ROW' clauseKindly suggest me

View 11 Replies View Related

Selection Action On Trigger

Oct 1, 2007

Hi all, i've created a trigger that fires 'INSTEAD OF INSERT, UPDATE, DELETE'.

It work's fine but need to know how i can know when was fired by insert,delete or update event so i can decide the actions to take without creating an individual trigger for each sentence.

Thanks in advance

View 1 Replies View Related

Using Trigger To Log Database Action.

Oct 5, 2006

Hi,

I have a database with 10 tables, and I need one trigger to each table that for insert, update and delete, get the registry that is been modified and insert these data in another table...

How can I do that ?



Thanks

View 1 Replies View Related

SQL Server 2012 :: Rule Of Thumb When To Disable Indexes?

Jun 19, 2014

It's often said or done that when inserting or updating into a 'large' table that disabling the non-clustered indexes can is needed for performance.

Now I know the obvious way to find out if this is best or not is by testing the different options. I was wondering if there was a rule of thumb to this?

Say you have a table with half a billion rows and 4 non-clustered indexes and are only updating half a million rows then sometimes disabling every night and re-enabling can take way more time than the actual update. Haven't found an articles advising to disable them when a table is over X rows and you are updating Y% of them...

View 5 Replies View Related

Disabilitazione Trigger [DISABLE TRIGGER]

Jul 20, 2005

Salve, non riesco a disabilitare un trigger su sqlserver nč da queryanalyzer, nč da enterprise manager.In pratica tal cosa riuscivo a farla in Oracle con TOAD, mentre qui nonriesco.Mi interessa disattivarlo senza cancellarlo per poi riattivarlo al bisognosenza rilanciare lo script di creazione.Grazie a tuttiHi I need to disable a DB trigger and I'm not able to do this neither withquery analyzer, neither with enterprise manager.I remeber this job was quite simple using TOAd in Oracle.I'm interested in making it disabled not delete it, without run creationscript.Thanks a lot to everybody.

View 4 Replies View Related

Can We Disable A Trigger In SQL 7.0

Jun 14, 2002

Is there a way to disable trigger for a time window and enable it when desired.

View 1 Replies View Related

Disable Trigger

Jul 12, 2001

Is it possible to disable a trigger to manually manipulate data without completely removing it? Thank you.

View 2 Replies View Related

Disable Trigger

May 11, 2001

Is it possible to disable a trigger in SQL Server 6.5?
Is so, how can i do that?

View 1 Replies View Related

Disable Trigger

Oct 25, 2004

Hi,

can I disable a trigger in Sqlserver 2000??? When i run a store procedure who works with one table i want that the trigger doesn´t work it. After that the trigger would be enabled again.

I know i can delete it and create it again but something like "ALTER TRIGGER DISABLED" would be ok.

Thanks.

View 6 Replies View Related

Disable Trigger

Mar 23, 2004

Sorry, may be it is very simple, but
how can I disable all trigger on a tabled under sql 2000

View 3 Replies View Related

Trigger Disable

Aug 9, 2007

Sorry to reopen a post, but I'm having the same problem. Worse, I can't change the trigger code right now.

My concerns with disabling triggers are:

1) DISABLE TRIGGER affects all sessions, not just the session doing the mass load
2) DISABLE TRIGGER is permanant until re-enabled, so if the mass load process fails (and if our TRY/CATCH blocks aren't perfect), then the triggers would remain disabled for normal OLTP use.
Any ideas on ways around this? I can identify all the work the triggers would have done and do it on my own. The problem is getting them not to do it!

View 9 Replies View Related

Disable Specific Trigger

Jul 26, 2004

I have a dilema, I need to have a delete trigger enabled to track user deletes to update an external history table. However, when the posting process runs for the table for which the delete trigger runs, all the records from that table are deleted. Th end result is that instead of capturing the specific deletes, it shows all recods being deleted. I know you can disable foreign keys and triggers as a whole, can you do it for specific triggers?

View 1 Replies View Related

How To Disable A Trigger In Duration?

Feb 21, 2005

Hello, everyone:

There is a trigger to monitor the modification on a table, and it turn on. For a special duration, I need to turn off this trigger to modify the table. And then turn on the trigger again.

Any help will be appreciated.

Thanks

ZYT

View 2 Replies View Related

Disable Trigger ONLY For My Insert?

Oct 1, 2007



Howdy all. Got a q someone might know something about.

Assume TableA and TableB, identical structure. TableA has an insert trigger.

I want to insert the contents of B into A, but i do NOT want the trigger to fire for my particular insert. During the insert (might be millions of records coping from B to A) i would like the trigger to continue to fire for anyone else that inserts data.

My research suggests that I need to BCP out from B to a file, then BULK INSERT from the file back to A. Anyone have any other ideas?

This was my first thoght, but of course, this will disable the trigger for ALL insert operations, not just mine:



Code Block
DISABLE MyInsertTrigger on TableA;
GO
insert into TableA
select * from TableB
GO
ENABLE MyInsertTrigger on TableA;
GO

View 3 Replies View Related

Disable Trigger Syntax?

Sep 4, 2007





Code Snippet
CREATE PROCEDURE Staff_NoteGroup_insert
(

@staffID AS int,
@owner AS int,
@subject AS varchar(256),
@message AS varchar(512),
@date_add AS DateTime
)
AS
BEGIN TRANSACTION SERIALIZABLE

DECLARE @id as int
SELECT @id = (SELECT MAX(id) FROM Staff_NoteGroup) + 1

IF @id IS NULL

SET @id = 1

INSERT INTO Staff_NoteGroup VALUES(@id, @staffID, @owner, @subject, GETDATE(), GETDATE())

IF @@error <> 0 BEGIN

ROLLBACK
RETURN
END

DISABLE TRIGGER Staff_Note_insert ON DATABASE
INSERT INTO Staff_Note VALUES(1, @id, @owner, @message, @date_add)
ENABLE TRIGGER Staff_Note_insert ON DATABASE

IF @@error <> 0 BEGIN

ROLLBACK
RETURN
END
COMMIT
GO






Below is the error message.


Msg 156, Level 15, State 1, Procedure Staff_NoteGroup_insert, Line 26

Incorrect syntax near the keyword 'TRIGGER'.

Msg 102, Level 15, State 1, Procedure Staff_NoteGroup_insert, Line 28

Incorrect syntax near 'ENABLE'.

Msg 102, Level 15, State 1, Procedure Staff_NoteGroup_insert, Line 33

Incorrect syntax near 'COMMIT'.


Where is the problem?
I'm using sql server 2005

Thanks,
Max

View 6 Replies View Related

How To Disable LOGON TRIGGER ?

May 25, 2007

SQL Server 2005 SP2 add LOGON TRIGGER feature,

but, if logon trigger have bug, it seems that anyone can connect to the sql server.



for example:

create trigger tr_logon1_bug

to all server

for logon

as

insert into t1 values(original_name(), getdate());



and, drop table 't1'.



the result, everyone fail to logon, even if sa. (may be..)

therefore, cannot disable/drop this trigger ...



So, Are there anyway to disable logon trigger,

or to connect by sa/Admin,

when logon trigger failed.



Regards,

View 3 Replies View Related

Can I Disable Trigger For A Single Sproc Only?

Jun 9, 2008

Hi

So, I know, after searching these forums, that it is possible to disable a trigger before updating a table and then enabling it again afterwords, for instance, from a stored procedure.

I might be dealing with hypotheticals here, but when I do a ...

ALTER TABLE table
{ ENABLE | DISABLE } TRIGGER
{ ALL | trigger_name [ ,...n ] }

... from a stored procedure, will it not be database wide?
Should I worry about another change to the table happening in the timespan in which the trigger is disabled (which it would be for during a single update), which the trigger should have caught?

Regards, Egil.

View 1 Replies View Related

Trigger On Enable / Disable SQL User

Mar 31, 2006

Is it possible to run a trigger whenever a SQL user is disabled or enabled? From what I've seen of various sysusers and syslogins tables there isn't a column that represents enabled or disabled.

View 6 Replies View Related

Disable/Enable A Trigger On A Replicated Table.

Apr 9, 2002

I have transaction replication setup on two SQL7 boxes and a nightly job runs a procedure that need to alter a table and disable a trigger. Since replication has been set up the disable doesn't work. Any way around this.

View 2 Replies View Related

SQL2000: Disable Trigger Not Allowed In Tables That Involved In Publication.

Apr 10, 2007

We have setup a replication in SQL2000:

We have DTS package automatically pouring data into the publishing database(source tables). During this process, we want to temporary disable certain triggers. However, the command

Alter table 'tbl' disable trigger 'abc' errored out. The error message said:

''Cannot alter the table 'tbl' because it is being published for replication."

I've digged more into this and found although it's not allowed to disable a triggers,

the SQLServer do allow delete the trigger and recreate them.

Is there any way to disable the trigger directly?

Thanks in advance,

Don



BTW:

I've used the following sql directly, however the trigger still fires.

UPDATE
sysobjects
SET
status = status|2048
WHERE
type = 'TR'
AND
parent_obj = OBJECT_ID (@table_name)



The only other way around now is to create stored procedures that dynamically create the trigger. Because our trigger is normmally larger than 8000 bytes. We have to create one stored procedure per trigger. This option is not acceptable because not only it takes quite a time, but also a maintainance nightmare.



View 8 Replies View Related

SQL Tools :: How To Disable Customer Improvement Program From Menu For Server MGMT Tools 2012

Mar 25, 2014

Am customizing SQL server MGMT tools 2012 for Mass deployment.Client had asked to remove Customer Feedback option from help menu.how to disable that.

View 6 Replies View Related

SQL 2012 :: CDC Is Disable

May 20, 2014

CDC is disabling when we do bulkinsertsupdateschange schema .how to findout why CDC disabled and how to prevent it ?

View 3 Replies View Related

SQL 2012 :: Enable / Disable AG Listener

Jul 3, 2014

How can one enabledisable Availability Group listener? I know AG listener can be deleted and added but didnt find anything to disable or enable that.

View 1 Replies View Related

SQL 2012 :: Disable File Indexing On Drives

Feb 25, 2014

Is it a best practice to disable "Allow files on this drive to have contents indexed" on NTFS drives used by SQL for its data, log, tempdb, etc?

In what I've read it seems to be a best practice for Filestream objects and Flash storage drives. We don't currently use Filestream objects or have Flash drives.

Are there any benefits or drawbacks to disabling this feature on an NTFS drive connected to SAN LUNs under mount points?

View 2 Replies View Related

SQL Server 2012 :: How To Create A DML Trigger

Jan 6, 2015

THe Scenario is We have Tables like parent and Child Table.

Like we have Child Table as Name AcademyContacts,In that we have Columns like

Guid(PK)Not Null,

AcademyId(FK), Not Null,

Name,Null

WorkPhone,Null

CellPhone,Null

Email Id,Null

Other.Null

Since we have given Null to ''Workphone'',''Cellphone '', ''Email ID''.when inserting the data into these table if the particular columns are empty while inserting also the data will get populate into the table.And I need is if these columns are ''Workphone'',''Cellphone'' , ''Email ID'' they cant insert the data into table.Like it must trigger like ''Please enter atleast one of these ''Workphone'',''Cellphone'' , ''Email ID'' columns.

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved