A  B  C  D  E  F  G  H  I  J  K  L  M  N  O  P  Q  R  S  T  U  V  W  X  Y  Z  special characters  sybase-tech-blog


Category: ASE: Functions: User, Login and Role Functions

user_id()

The user function user_id() returns the "id" of the user specified in the parameter "db_user_name" for the current session, i.e. it returns the id for a database user or the currently logged in user.

Syntax of the User Function user

    user_id([db_user_name])
    

The parameter of the User Function user_id()

db_user_name
The parameter "db_user_name" is an optional placeholder for an arbitrary database user, i.e. the name of the user of a database, who was created using the system procedure sp_adduser and is stored in the system table sysusers The parameter "db_user_name" must be set in quotes. If the specified user does not exist, NULL If the parameter "db_user_name" is not specified, the function user_id() returns the "id" of the user of the current session. Every user with an active sa_role automatically becomes dbo, though and consequently, the return value is always "1". To determine the actual current "id" it is required to switch off the sa_role by issuing the command "set role sa_role off" (see also: set role), before executing the function user_id(). The command can only be executed if a valid user account exists in the current database. If not, an error message is returned.

Example for the User Function user

    select user_id()
go
-----
1

Returns the id of the user in the current session.

    select user_id("existing_user_name")
go
-----
153

Returns the id of the specified user.

    select user_id("not_existing_user_name")
go
-----
NULL

Retuns NULL, because the user has not been created.

setuser,
sp_addalias,
sp_addgroup,
sp_addlogin,
sp_adduser,
sp_changegroup,
sp_configure "check password for digit",
sp_configure "minimum failed logins",
sp_configure "minimum password length",
sp_configure "systemwide password expiration",
sp_displaylogin,
sp_dropalias,
sp_dropgroup,
sp_droplogin,
sp_dropuser,
sp_helpgroup,
sp_helpuser,
sp_locklogin,
sp_modifylogin,
sp_password,

See also:

ASE T-SQL - Aggregate Functions,
ASE T-SQL - User,
mut_excl_roles(),
proc_role(),
role_contain(),
role_id(),
role_name(),
show_role(),
suser_id(),
suser_name(),
user,
user_name(),
valid_name(),
valid_user().