Adds a security account for a new user in the current database. This procedure is included for backward compatibility. Use sp_grantdbaccess.
sp_adduser [@loginame =] 'login'
[,[@name_in_db =] 'user']
[,[@grpname =] 'group']
0 (success) or 1 (failure)
SQL Server usernames can contain from 1 to 128 characters, including letters, symbols, and numbers. However, usernames cannot:
After a user has been added, use the GRANT, DENY, and REVOKE statements to define the permissions controlling the activities performed by the user.
Use sp_helplogin to display a list of valid login names.
Use sp_helprole to display a list of the valid role names. When specifying a role, the user automatically gains the permissions that are defined for the role. If a role is not specified, the user gains the permissions granted to the default public role. To add a user to a role, a value for username must be supplied. (username can be the same as login_id.)
To access a database, a login must be granted access by using sp_adduser or sp_grantdbaccess, or the guest security account must exist in the database.
sp_adduser cannot be executed inside a user-defined transaction.
Only dbo can execute sp_adduser.
This example adds the user Victoria to the existing fort_mudge role in the current database, using the existing login Victoria.
EXEC sp_adduser 'Victoria', 'Victoria', 'fort_mudge'
This example adds the default username Margaret to the current database for the login Margaret, which belongs to the default public role.
EXEC sp_adduser 'Margaret'
This example adds the Haroldq login to the current database with a username of Harold, which belongs to the fort_mudge role.
EXEC sp_adduser 'Haroldq', 'Harold', 'fort_mudge'
sp_addrole | sp_grantlogin |
sp_dropuser | sp_helpuser |
sp_grantdbaccess | System Stored Procedures |