Solved

SQL Set current user as default value or Binding

Posted on 2010-11-15
4
1,083 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Log Backup 2 21
Troubleshooting Methodology - steps 3 36
Upgrading an old legacy SQL server 20082 to 2014 - TSQL compatibility 3 36
SQL profiler equivalent in MS-Access 3 40
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

929 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now