SQL Server - display username in column

We have a database of SQL Server 2012, which is used by 4 developers, allows us to call them user1, user2, user3, user4.

I want to create a column in one of the tables in order to call the User_Input column, this column should show the name of the developer user who inserts any data, is this possible? For example, if user2 inserted a new record, the column User_Input should display user2.

Please let me know if SQL Server does not support this, and if there is any other solution, I was looking for @@ functions for SQL Server and not them, it seems I got a username.

+4
source share
2 answers

SYSTEM_USER .

:   SELECT SYSTEM_USER

MSDN SYSTEM_USER :

SYSTEM_USER DEFAULT CREATE TABLE ALTER TABLE. .

DEFAULT, SYSTEM_USER User_Input.

CREATE TABLE MyTable 
(
   ID int, 
   Value varchar(30), 
   User_Input varchar(200) DEFAULT SYSTEM_USER
)   
+2

, , .

SELECT SYSTEM_USER

/ .

CURRENT_USER , , .

0

Source: https://habr.com/ru/post/1530646/


All Articles