Which one should I use to record update made by users?
SYSTEM_USER
, orORIGINAL_LOGIN()
, orSUSER_SNAME()
SQL Server USER_NAME() Function The USER_NAME() function returns the database user name based on the specified id. If no id is specified, this function will return the name of the current user.
Pass the userid and password to the procedure. Storeprocedure(uname varchar,pwd varchar) { check whether the record exists for that uname and pwd. (something like select count(*) into intcount from users where upper(username)=uname and password=pwd) if intcount>0 return true. else return false. }
Open up SQL Server Configuration Manager (search for it in the Start menu). Click on SQL Server Services . The instance name of SQL Server is in parenthesis inline with SQL Server service. If it says MSSQLSERVER, then it's the default instance.
Calls to USER_ID by a Windows principal mapped to an implicit user will return the ID of the implicit user. USER_ID can be used in a select list, in a WHERE clause, and anywhere an expression is allowed. For more information, see Expressions (Transact-SQL).
SYSTEM_USER
returns the current executing context, so this can return an impersonated context
ORIGINAL_LOGIN()
returns the identity of the user that initially connected to the instance, so regardless whether the context is impersonated or not it will yield the original user that logged in, good for auditing.
SUSER_SNAME()
this is used if you want to get the username by SID so SUSER_SNAME
can be invoked with a parameter like such SUSER_SNAME([server_user_sid])
but the SID is optional if you don’t pass that parameter the current user is returned.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With