Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Create Trigger
Message
 
 
À
07/10/2009 01:09:19
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Titre:
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Desktop
Divers
Thread ID:
01427973
Message ID:
01427986
Vues:
44
Do you have a PK in your table wich is never changed? If yes, then
create trigger tr_Test_Update on Test for update as
begin
	update T set FollowID = I.ID from Test T 
	inner join Deleted Del on T.FollowID = Del.ID 
	inner join Inserted I on I.RealPK = Del.RealPK
end
>not working correctly
>
>let say TableA have this row
>
>id name followid
>--- --------- -----------
>a a e
>b b e
>c c e
>d d e
>e e null
>
>when changing e to f
>
>id name followid
>--- --------- -----------
>a a f
>b b f
>c c f
>d d f
>f e null
>
>
>
>
>>>Can someone help me with this :-
>>>
>>>Table A
>>>-----------
>>>id
>>>name
>>>followid (follow another record id)
>>>
>>>
>>>i need to create a trigger on Table A so whenever the id change,
>>>a trigger will fire on Table A to update all the followid that have the same value as the inserted.id
>>>
>>>
>>>thanks in advance
>>
>>You need to be careful to not fall into infinite loop
>>
>>create trigger tr_TableA_Update ON TableA for UPDATE
>>AS
>>  BEGIN
>>         update TableA set FollowID = Inserted.ID from TableA 
>>inner join Inserted on ID = Inserted.ID inner join Deleted on TableA.FollowID = Deleted.ID
>> END
If it's not broken, fix it until it is.


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

Click here to load this message in the networking platform