Returns 1 if the specified ID is a valid user or alias in at least one database.
valid_user(server_user_id [, database_id])
is a server user ID. Server user IDs are stored in the suid column of syslogins.
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.
User with an suid of 4 is a valid user or alias in at least one database:
select valid_user(4)
--------------- 1
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
valid_user returns 1 if the specified server_user_id is a valid user or alias in the specified database_id.
If you do not specify a database_id, or if it is 0, valid_user determines if the user is a valid user or alias on at least one database.
ANSI SQL – Compliance level: Transact-SQL extension.
You must be a System Administrator or a System Security Officer to use this function on a server_user_id other than your own.
Documentation Transact-SQL Users Guide
System procedures sp_addlogin, sp_adduser