Returns the ID number of the specified user or of the current user in the database.
user_id([user_name])
select user_id()
------ 1
select user_id("margaret")
------ 4
user_id, a system function, returns the user’s ID number. For general information about system functions, see Transact-SQL Users Guide.
user_id reports the number from sysusers in the current database. If no user_name is supplied, user_id returns the ID of the current user. To find the server user ID, which is the same number in every database on the SAP ASE server, use suser_id.
Inside a database, the “guest” user ID is always 2.
Inside a database, the user_id of the database owner is always 1. If you have the sa_role active, you are automatically the database owner in any database you are using. To return to your actual user ID, use set sa_role off before executing user_id. If you are not a valid user in the database, the SAP ASE server returns an error when you use set sa_role off.
setuser in Reference Manual: Commands
Transact-SQL Users Guide
ANSI SQL – Compliance level: Transact-SQL extension.
Any user can execute user_id.