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)
 Global level trigger

Author  Topic 

Sachin.Nand

2937 Posts

Posted - 2010-12-17 : 00:23:53
Hi Guys,

I have a GDR set up in TFS.Whenever the GDR is run to create a new database it inserts a default row in all the tables so that the integrity does not fail when developers run unit test cases.All the id's for the default row inserted from GDR is has a value 0.

What I need to know is that is there something called as a global level trigger where the user does delete a record with id 0 from any of tables?
I cannot write trigger for individaul table as the no of tables are 430.

PBUH

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2010-12-17 : 13:07:00
There is not a mechanism like you mention. However, you can write a script that will generate the necessary code:[CODE]select
'DELETE FROM ' + Name + ' WHERE ID = 0;'
FROM sys.tables'[/CODE]You may need to adjust for the name of the column or to filter out unwanted tables but you get the basic idea.

=======================================
Elitism is the slur directed at merit by mediocrity. -Sydney J. Harris, journalist (1917-1986)
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-12-18 : 00:25:08
Sorry I made a type error.
What I meant was the developers should NOT be able to delete any record which has Id=0 when they are running Unit test cases.
If they try to do it from the tables the "Global Trigger" should not allow to do it.

PBUH

Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2010-12-20 : 11:26:00
You can create a database trigger and add your logic to that.

=======================================
Elitism is the slur directed at merit by mediocrity. -Sydney J. Harris, journalist (1917-1986)
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-12-22 : 01:40:42
Thanks for the reply.

But can you tell me how can I set it ?

PBUH

Go to Top of Page
   

- Advertisement -