Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1146
  • Last Modified:

SQL Set current user as default value or Binding

When creating a table, Can I set a column to automatically grab the user's name when a new row is created?
0
Cree
Asked:
Cree
1 Solution
 
Darius GhassemCommented:
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
 
CreeAuthor Commented:
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
 
sameer2010Commented:
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
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
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

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now