views:

26

answers:

1

Hi. Can anybody tell me how can I update a column of a record when it is inserted to the database. Here's the pseudocode that I want.

if( mytable.OriginalId == null )
    mytable.OriginalId = Scope_Identity();
+1  A: 

This would be contradictory I think. Either OriginalId is set or it isn't on insert.

If it isn't where does Scope_Identity() get it's value from? If it's from another column then would it not be better to use a computed column?

Sorry, it's not clear what the overall objective is... you would not normally use a trigger especially if OriginalId is part of the PK

gbn
Sorry, I should have mentioned. The PK is another column called "Id".
Mohammadreza
Thanks. And should OriginalId always be the same as ID? or different?
gbn
If the user sets it to null it should be the same as ID otherwise it should be whatever user wants.
Mohammadreza