Showing posts with label triggers. Show all posts
Showing posts with label triggers. Show all posts

Thursday, March 29, 2012

easy way to mark all the fk's and triggers NFR?

Is there a script somehwhere which would alter all constraints and
recreate/alter triggers with NFR property set to 1?
or
would one of you guys know of an easy way to do it?
Thank you.
Tejas.
Following should help. PLEASE TEST IT BEFORE USING IT IN A REAL ENVIRONMENT.
You may uncomment the commented lines if trying to do the same for individual
tables.
SET NOCOUNT ON
GO
DECLARE@.tbl_namevarchar(50)
--SELECT@.tbl_name = 'tbl_name'
/*
Creating the command to drop constraints on the table
*/
SELECT'ALTER TABLE ' + object_name(fkeyid) + ' DROP CONSTRAINT ' +
object_name(constid) + CHAR(10) + 'GO' + CHAR(10)
FROMsysreferences
-- WHERE object_name(fkeyid) = @.tbl_name
-- ORobject_name(rkeyid) = @.tbl_name
ORDER BY object_name(fkeyid)
/*
Creating the command to re-create all the dropped constraints
*/
SELECT'ALTER TABLE ' + object_name(a.fkeyid) + ' ADD CONSTRAINT ' +
object_name(constid) + ' FOREIGN KEY (' + b.name + ') REFERENCES ' +
object_name(a.rkeyid) + '(' + c.name + ') NOT FOR REPLICATION' + CHAR(10) +
'GO' + CHAR(10)
FROM sysforeignkeys a,
syscolumns b,
syscolumns c
WHERE a.fkey = b.colid
AND a.fkeyid = b.id
AND a.rkey = c.colid
AND a.rkeyid = c.id
-- AND (object_name(a.rkeyid) = @.tbl_nameOR
-- object_name(a.fkeyid) = @.tbl_name)
ORDER BY object_name(a.fkeyid)
GO
"Tejas Parikh" wrote:

> Is there a script somehwhere which would alter all constraints and
> recreate/alter triggers with NFR property set to 1?
> or
> would one of you guys know of an easy way to do it?
> Thank you.
> Tejas.

Tuesday, March 27, 2012

Easy way to copy Triggers

I'm looking for an easy way to copy triggers from my development database to
my production database without having to copy and paste the trigger to each
table.
You could generate a SQL script... e.g. open Enterprise Manager, right-click
a table, choose All Tasks > Generate SQL Script, choose all tables, and make
sure that on the options tab, you select "script triggers"... then you can
just modify the resulting script to only have the triggers, assuming all of
the tables actually exist in the production database.
You could also try using the system tables to generate a script to create
all triggers:
select sc.text + CHAR(13) + CHAR(10) + 'GO'
from
sysobjects so INNER JOIN
syscomments sc ON sc.id = so.id
where so.xtype='tr'
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Geoff" <cbsinc@.earthlink.net> wrote in message
news:pcIac.10178$lt2.7981@.newsread1.news.pas.earth link.net...
> I'm looking for an easy way to copy triggers from my development database
> to
> my production database without having to copy and paste the trigger to
> each
> table.
>

Easy way to copy Triggers

I'm looking for an easy way to copy triggers from my development database to
my production database without having to copy and paste the trigger to each
table.You could generate a SQL script... e.g. open Enterprise Manager, right-click
a table, choose All Tasks > Generate SQL Script, choose all tables, and make
sure that on the options tab, you select "script triggers"... then you can
just modify the resulting script to only have the triggers, assuming all of
the tables actually exist in the production database.
You could also try using the system tables to generate a script to create
all triggers:
select sc.text + CHAR(13) + CHAR(10) + 'GO'
from
sysobjects so INNER JOIN
syscomments sc ON sc.id = so.id
where so.xtype='tr'
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Geoff" <cbsinc@.earthlink.net> wrote in message
news:pcIac.10178$lt2.7981@.newsread1.news.pas.earthlink.net...
> I'm looking for an easy way to copy triggers from my development database
> to
> my production database without having to copy and paste the trigger to
> each
> table.
>