Link to home
Start Free TrialLog in
Avatar of damixa
damixaFlag for Denmark

asked on

trigger to populate username field in sql server

I need to create a trigger that populates a field named "CreatedBy" with the username of the person who creates the record. I already have a trigger that creates an audit log of when it was cretated like:

ALTER TRIGGER [dbo].[trg_CreatedDate] 
ON dbo.mytable
AFTER Insert
AS
    UPDATE dbo.mytable
    SET CreatedDate = GETDATE()
    WHERE ID IN (SELECT DISTINCT ID FROM Inserted)

Open in new window


thanks
ASKER CERTIFIED SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of damixa

ASKER

Thanks guys, both excellent ideas.