Update inserted record on Insert Triggers

jabcoco
jabcoco used Ask the Experts™
on
Hi expert.
I have a quit simple table for my example (PK_Users (identity,int), Name (varchar(100)), MyInfo (varchar(100)).

So what i need is a triggers on insert who update the "MyInfo" field value before it's save on the database.

You can use my simple table with 3 fields has example.

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Billing Engineer
Most Valuable Expert 2014
Top Expert 2009
Commented:
>who update
do you know where to take that info from?
aka, that you are only able to get the "sql login" information, not necessarily the end-user (windows account) unless you are using windows authentication.
create trigger trg_update_who
  on yourtable
 for insert
as
 update t
   set myinfo = suser_name()
  from inserted i
  join yourtable t
    on t.pk_users = i.pk_users

Open in new window

Author

Commented:
Great job.
Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial