Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Set current user as default value or Binding

Posted on 2010-11-15
4
Medium Priority
?
1,120 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

660 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