SQL Server/T-SQL Tutorial/System Functions/SYSTEM USER

Материал из SQL эксперт
Перейти к: навигация, поиск

Reporting Current User and Login Context

The SYSTEM_USER function returns the Windows or SQL login name.
The USER function returns the current user"s database user name.
6>
7> SELECT SYSTEM_USER -- Login
8> GO

------------------------------------------------------------------------------------------------------------------------
--------
BCE67B1242DE45A\Administrator

(1 rows affected)


select SYSTEM_USER

10> SELECT CURRENT_TIMESTAMP, USER, SYSTEM_USER, CURRENT_USER,
11> SESSION_USER
12> GO

----------------------- -------------------------------------------------------------------------------------------------------------------------------- -----------------------------------------------
--------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------
---------- --------------------------------------------------------------------------------------------------------------------------------
2008-08-17 13:20:57.503 dbo                                                                                                                              J\Administrator
                                                                                  dbo
           dbo
(1 rows affected)


Use SYSTEM_USER as a default value

8> CREATE TABLE FunctionEx
9> (EntryDBUser varchar(128) DEFAULT SYSTEM_USER)
10> GO
1>
2>
3> drop table FunctionEx;
4> GO