Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
sql_server 217
t-sql 211
tsql 116
sqlserver 96
BRH 78
#SQLServer 66
#TSQL 56
SQL Server 34
function 11
SSMS 9

Archive · View All
August 2007 17
August 2010 8
June 2012 7
June 2011 7
November 2007 7
August 2012 6
May 2012 6
November 2011 6
August 2011 6
October 2011 6

Madhivanan's TSQL Blog

SQL Server - Quick and Easy auditing using host_name() and user_name() functions

Aug 4 2010 2:00AM by Madhivanan   

For various reasons you may need to audit some activities on certain tables.Usually you can use triggers for this.Sometimes you may want to know the system from which data are added or the user who added data.In these cases, you can use two functions host_name() and user_name()

Host_name()
This function is used to return the name of the system from which the code is executed. The following will return your system name

select host_name()

user_name()
This function is used to return the name of the user identified by a userid. The following will return the user name for the particular userid.

select user_name(1)

If you omit userid parameter by default current user of the session is considered and it returns the name of the user who is currently connected to the session

select user_name()

Now you can use these functions to know the user who adds data to a table as well as the system in which data come from. Consider the follwoing table that has two columns wirh default values of these function

declare @test table
(
	productid varchar(10), amount decimal(12,2), 
	system_name varchar(100) default host_name(),
	username varchar(100) default user_name()
)
insert into @test(productid,amount)
select 'P001',7234.45 union all
select 'P002',2000.10

select * from @test

The result is

productid  amount                                  system_name username
---------- --------------------------------------- ----------- ----------
P001       7234.45                                 SYS100      dbo
P002       2000.10                                 SYS100      dbo

Tags: t-sql, sql_server, sqlserver, tsql, BRH, #TSQL, auditing, user_name(), host_name(), #DBA, dba,


Madhivanan
3 · 39% · 12472
2
 
0
Lifesaver
 
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

"SQL Server - Quick and Easy auditing using host_name() and user_name() functions" rated 5 out of 5 by 2 readers
SQL Server - Quick and Easy auditing using host_name() and user_name() functions , 5.0 out of 5 based on 2 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]