Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Dynamic SQL Statement Question

Author  Topic 

Lijo Cheeran Joseph
Posting Yak Master

123 Posts

Posted - 2011-07-21 : 07:47:34
Hi,

I am trying to run a SQL statement to disable trigger on a table. I am getting the following error.
"Could not locate entry in sysdatabases for database 'DISABLE TRIGGER dbo'. No entry found with that name."

How do I modify it to run successfully?

DECLARE @Statement VARCHAR(1000)
SET @Statement = 'DISABLE TRIGGER dbo.Trigger_audit_Area ON dbo.Area'
EXEC @Statement

Thanks

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-07-21 : 07:58:24
alter table YourTable disable trigger triggername

and I see no need for dynamic sql...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Lijo Cheeran Joseph
Posting Yak Master

123 Posts

Posted - 2011-07-21 : 08:01:47
I have 300 tables. I want to disable the tirggers on all of them programmatically. Can you please tell me how to do that?
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-07-21 : 08:10:03
Try:

use YourDatabase
go
sp_msforeachtable 'ALTER TABLE ? DISABLE TRIGGER all'



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Lijo Cheeran Joseph
Posting Yak Master

123 Posts

Posted - 2011-07-25 : 11:33:49
Thanks....
sp_msforeachtable helped.
Go to Top of Page
   

- Advertisement -