user_id

Returns the ID number of the specified user or of the current user in the database.

Syntax

user_id([user_name])

Parameters

Examples

Usage

  • 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.

See also:
  • setuser in Reference Manual: Commands

  • Transact-SQL Users Guide

Standards

ANSI SQL – Compliance level: Transact-SQL extension.

Permissions

Any user can execute user_id.

Related reference
suser_id
user_name