Solved

SQL Set current user as default value or Binding

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

757 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

22 Experts available now in Live!

Get 1:1 Help Now