Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Trigger
Message
De
10/01/2005 08:10:25
 
 
À
06/01/2005 08:07:48
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Titre:
Divers
Thread ID:
00974653
Message ID:
00975613
Vues:
17
Hi Welington,

If you want to trigger an update to a field in a master table and update the child tables related records try this example. I haven't had time to test it but it should work.
CREATE TRIGGER [UPDATE] ON [dbo].[master_table] FOR UPDATE
AS

--Is the key field updated
IF UPDATE(id)
BEGIN
	declare @old_id as int
	declare @new_id as int

	--Before update
	set @old_id = (select id from deleted)

	--After update
	set @new_id = (select id from inserted)

	--Update child table
	update child_table set id = @new_id where id = @old_id
END

GO
Magnus Nordin
VFP MCP

"We have tested the GUI on 5-year olds. Why? Beacuse they aren't braindead!"
Michael Spindler, Apple

Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform