dbTalk Databases Forums  

Trigger After Delete - I would need a Trigger Before Delete

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Trigger After Delete - I would need a Trigger Before Delete in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
candide_sh@yahoo.de
 
Posts: n/a

Default Trigger After Delete - I would need a Trigger Before Delete - 07-17-2007 , 10:04 AM






hello,
I googled around some time but I found no solution for this issue
(SS2000).

I have a table tblB which has to be filled whenever in another table
tblA records are inserted, updated or deleted.
So I created one trigger which works fine for inserts and updates and
fills my tblB. tblB is filled with other fields which I get from a
view vwC.

The issue is about this view. When in tblA a record is deleted, the
corresponding record in vwC does not exist and I can't fill tblB. I
tried around with INSTEAD OF -Trigger and got error message because
tblA has RI cascades so this is not possible. A temp table could be
the right way? Can you show me an example?

thanks
--
candide_sh


Reply With Quote
  #2  
Old   
Roy Harvey
 
Posts: n/a

Default Re: Trigger After Delete - I would need a Trigger Before Delete - 07-17-2007 , 11:03 AM






I believe you will have to do it without the view. You would need the
view to join the DELETED table to those other tables, and no view can
reference DELETED. In the trigger, in the FROM clause, replace the
reference to the view with a derived table using the same SELECT as
the view. So instead of:

FROM ViewName

you will need

FROM (<SELECT.....>) as ViewName

Note that if you have an alias assigned to the view reference that
would go after the "as" rather than ViewName.

Roy Harvey
Beacon Falls, CT

On Tue, 17 Jul 2007 08:04:59 -0700, candide_sh (AT) yahoo (DOT) de wrote:

Quote:
hello,
I googled around some time but I found no solution for this issue
(SS2000).

I have a table tblB which has to be filled whenever in another table
tblA records are inserted, updated or deleted.
So I created one trigger which works fine for inserts and updates and
fills my tblB. tblB is filled with other fields which I get from a
view vwC.

The issue is about this view. When in tblA a record is deleted, the
corresponding record in vwC does not exist and I can't fill tblB. I
tried around with INSTEAD OF -Trigger and got error message because
tblA has RI cascades so this is not possible. A temp table could be
the right way? Can you show me an example?

thanks

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.