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_name()

The user function user_name() returns the name of the user specified by the "id$quot; in parameter "db_user_id" in the current session.

Syntax of the User Function user

    user_name([db_user_id])
    

The parameter of the User Function user_name()

db_user_id
The parameter "db_user_id" is an optional placeholder for an arbitrary "id" of a database user, i.e. the "id" of a 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_id" must be set in quotes. If the specified "id" does not exist, NULL is returned. If the parameter "db_user_id" is not specified, the function user_name() returns the name of the user in the current session. Because every user with an active sa_role is automaticall dbo, i.e. the "Database owner", the output might only contain "dbo". In order to display the actual user name in this case, the sa_role needs to be switched off by executing the command "set role sa_role off" (see also: set role), before executing the function user_name(). The command can only be executed though, if the user has a valid account in the current database. Otherwise, an error message is returned.

Example for the User Function user

    select user_name()
go
-----
dbo

Returns the name of the user in the current session.

    select user_name("existing_user_id")
go
-----
db_user_name

Returns the name of the user specified.

    select user_name("not_existing_user_id")
go
-----
NULL

Returns NULL, because the "id " does not exist.

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_id(),
valid_name(),
valid_user().