Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Delete in child table should update parent modidate
Message
 
 
À
03/03/2003 10:47:30
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Conception bases de données
Divers
Thread ID:
00760229
Message ID:
00760442
Vues:
12
>If you are doing the delete with a SP, you can add the update to it's transaction. If you are using Client side SQL then you can use a delete trigger.

Thanks, this works
IF EXISTS (SELECT name 
	   FROM   sysobjects 
	   WHERE  name = N'tr_CartContent_Delete' 
	   AND 	  type = 'TR')
    DROP TRIGGER tr_CartContent_Delete
GO

CREATE TRIGGER tr_CartContent_Delete
ON CartContent
FOR DELETE
AS 
/*
CREATED BY:     Nadya Nosonovsky
CREATED ON:     03/03/2003
PURPOSE:        This delete trigger updates ModiType and
                LastModTs fields in Cart table, 
                when the record is deleted from the CartContent table
 */

BEGIN

UPDATE Cart
 SET LastModTs=GetDate(), ModiType = 'D'
 FROM Cart, Deleted WHERE Cart.CartID = Deleted.CartID

END

GO
-- To test
DELETE FROM CartContent WHERE CartContentID in (45,46,47)
select count(*) as Recs, CartContentID from CartDetail where CartContentID in (45,46,47) group by CartContentID
What should I do for error handling?
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform