Returns the ID number of the specified user or of the current user in the database.
user_id([user_name])
is the name of the user.
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 “System functions”.
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 Adaptive 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, Adaptive Server returns an error when you use set sa_role off.
ANSI SQL – Compliance level: Transact-SQL extension.
You must System Administrator or System Security Officer to use this function on a user_name other than your own.
Commands setuser