valid_user

Description

Returns 1 if the specified ID is a valid user or alias in at least one database.

Syntax

valid_user(server_user_id [, database_id])

Parameters

server_user_id

is a server user ID. Server user IDs are stored in the suid column of syslogins.

database_id

is the ID of the database on which you are determining if the user is valid. Database IDs are stored in the dbid column of sysdatabases.

Examples

Example 1

User with an suid of 4 is a valid user or alias in at least one database:

select valid_user(4)
---------------
              1

Example 2

User with an suid of 4 is a valid user or alias in the database with an ID of 6.

select valid_user(4,6)
---------------
              1

Usage

Standards

ANSI SQL – Compliance level: Transact-SQL extension.

Permissions

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

Granular permissions enabled

With granular permissions enabled, you must have manage any login or manage server permission to execute valid_user on a server_user_id other than your own.

Granular permissions disabled

With granular permissions disabled, you must be a user with sa_role or sso_role to execute valid_user on a server_user_id other than your own.

See also

Documentation Transact-SQL Users Guide

System procedures sp_addlogin, sp_adduser