How to get Windows Log-in User Name for a SQL Log in User
There is no link between a SQL login and the NT username.
You asked similar here: How to find out user name and machine name to access to SQL server
The WMI approach will be ambiguous if more than 1 user is logged into the client PC (eg service accounts, remote user via mstsc etc). Any approach like this will require admin rights on the client PC too for the account used.
I doubt you can do it in real time.
All you can do is record the client_net_address
in sys.dm_exec_connections
and backtrack from there, perhaps via WMI but not from SQL Server itself.
Do you need the username though? Or just the client PC so you can change the app connection string?
You final solution is to change the sa password and see who calls, if you only have relatively few SQL connections
I want to get windows login name instead of SQL login name
Use SUSER_NAME()
or SUSER_SNAME()
If neither of these are returning your AD account you logged in via, check you are using AD trusted connections and not SQL auth.
https://learn.microsoft.com/en-us/sql/t-sql/functions/suser-sname-transact-sql?view=sql-server-2017
Get login name in SQL SERVER
execute as login = 'LCF\jmp'
select distinct name
from sys.login_token
where principal_id > 0
and type = 'WINDOWS GROUP';
Change Login name (Windows user) for an existing SQL user on the Database server
When SQL Server user domain name changes, at this time, we still want to keep the current database user setting and don't want to recreate those users, we can use SQL script to update the user domain as follow:
ALTER USER [abcd] WITH LOGIN = [DomainB\abcd], NAME = [abcd]
I am glad that works for you.
Get Full name of User logged-in using login Details in C# windows form Application
You can use an outer or left join to represent everything in one table and only the matched items in the other.
select
*
FROM
TABLEALL
LEFT JOIN
TABLESOME
ON
TABLEALL.ID = TABLESOME.ID
Related Topics
Is There Any Better Option to Apply Pagination Without Applying Offset in SQL Server
Split String by Comma in SQL Server 2008
How to Read a Text File Using T-Sql
Oracle 10: Using Hextoraw to Fill in Blob Data
SQL Server Regular Expressions
How to Detect Query Which Holds the Lock in Postgres
MySQL - How to Count All Rows Per Table in One Query
Ignore Certain Columns When Using Bulk Insert
Efficient Way to String Split Using Cte
Laravel Eloquent to Join Table and Count Related
SQL Query of Haversine Formula in SQL Server
How to Get Count() and Rows from One SQL Query in SQL Server
Selecting Multiple Max() Values Using a Single SQL Statement