setuser

Allows a database owner to impersonate another user.

Syntax

setuser ["user_name"]

Examples

Usage

  • The database owner uses setuser to adopt the identity of another user in order to use another user’s database object, to grant permissions, to create an object, or for some other reason.

  • Except for sessions run by login account “sa,” when the database owner uses the setuser command, the SAP ASE server checks the permissions of the user being impersonated instead of the permissions of the database owner. The user being impersonated must be listed in the sysusers table of the database.

  • setuser affects permissions only in the local database. It does not affect remote procedure calls or accessing objects in other databases.

  • setuser remains in effect until another setuser command is given or until the current database is changed with the use command.

  • setuser has no effect when creating a database.

  • Executing setuser with no user name reestablishes the database owner’s original identity.

  • system administrators can use setuser to create objects that are owned by another user. However, since a system administrator operates outside the permissions system, she or he cannot use setuser to acquire another user’s permissions.

Standards

ANSI SQL – Compliance level: Transact-SQL extension.

Permissions

The permission checks for setuser differ based on your granular permissions settings.

SettingDescription
Enabled

With granular permissions enabled, you must have setuser privilege to run setuser. setuser privilege is granted to the database owner by default.

Disabled

With granular permissions disabled, setuser privilege defaults to the database owner and is not transferable.

Auditing

Values in event and extrainfo columns of sysaudits are:

InformationValues
Event

84

Audit option

setuser

Command or access audited

setuser

Information in extrainfo
  • Roles – current active roles

  • Keywords or options – NULL

  • Previous value – NULL

  • Current value – NULL

  • Other information – Name of the user being set

  • Proxy information – original login name, if a set proxy is in effect

Related reference
grant
revoke
use