Solved

SQL Set current user as default value or Binding

Posted on 2010-11-15
4
1,092 Views
Last Modified: 2012-06-27
When creating a table, Can I set a column to automatically grab the user's name when a new row is created?
0
Comment
Question by:Cree
4 Comments
 
LVL 59

Expert Comment

by:Darius Ghassem
ID: 34141050
The link explains in detail on adding a trigger that will update the column when the row is insterted.

http://sqlserver2000.databases.aspfaq.com/how-do-i-audit-changes-to-sql-server-data.html
0
 

Author Comment

by:Cree
ID: 34141172
Thanks,
I did it but i guess it is not doing what I want it to do.

I have this table linked to Access.  When a user is adding a new row to the table (via a report) I want the USER column to put their sql user name in there automatically.

0
 
LVL 13

Expert Comment

by:sameer2010
ID: 34141867
But it may not be necessary to have SQL server name for every user who can access Access.
We can always capture user name of user accessing Access and pass it on to MSSQL for update.
0
 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 500 total points
ID: 34143722
Yes, you can create USER (Don't use USER since it is a reserved keyword and hence used user_name_log) column like this

create table test ( a int identity, b int, c varchar(10), user_name_log varchar(100) default suser_name())
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question