retrieve login name | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

retrieve login name

Hi, I’m working on a ‘logging’-table and want to know how I can retrieve the loginname from the person who is making the changes. In my trigger I used user but that gives back dbo and what i’m looking for is the loginname.
Using Mixed-mode authentication and i’m the owner of the db. In the end i want something like:
INSERT INTO [dbo].[employee](date, tablename, recordnr, Modified_by)
VALUES(GETDATE(),’tablename’,@@identity, ……) Hope someone can point me in the right direction Maurice
Have a look at the following
select user_name() select system_user select suser_sname() you could use something along the lines of, INSERT INTO dbo.Employee(date, tablename, recordnr, Modified_by)
SELECT getdate(), ‘TABLE’, @@identity, system_user
Thomas, Thanks for the reply. I used system_user and it gave back exactly what I was looking for. Thank you for the assistance. Maurice
Why is everyone asking about INSERT statements with VALUES clauses for triggers? If you insert/update/delete multiple rows, the corresponding trigger(s) will fire once for all rows. If you already know about the deleted and inserted snapshots, you must also be aware of the fact that they can contain multiple rows. If you then want to use a VALUES clause to carry some of the new info (like the new identity values) to a log table, then please use a SELECT statement instead – this will handle any number of rows, even if it is just 1. Check the CREATE TRIGGER syntax in Books Online – it explains the concepts pretty well.