The Database Owner or a System Administrator can use sp_adduser to add a user to a specific database. The user must already have an Adaptive Server login. The syntax is:
sp_adduser loginame [, name_in_db [, grpname]]
where:
loginame – is the login name of an existing user.
name_in_db – specifies a name that is different from the login name by which the user is to be known inside the database.
You can use this feature to accommodate users’ preferences. For example, if there are five Adaptive Server users named Mary, each must have a different login name. Mary Doe might log in as “maryd”, Mary Jones as “maryj”, and so on. However, if these users do not use the same databases, each might prefer to be known simply as “mary” inside a particular database.
If no name_in_db parameter is given, the name inside the database is the same as loginame.
This capability is different from the alias mechanism described in “Using aliases in databases”, which maps the identity and permissions of one user to another.
grpname – is the name of an existing group in the database. If you do not specify a group name, the user is made a member of the default group “public.” Users remain in “public” even if they are a member of another group. See “Changing a user’s group membership” for information about modifying a user’s group membership.
sp_adduser adds a row to the sysusers system table in the current database. When a user has an entry in the sysusers table of a database, he or she:
Can issue use database_name to access that database
Will use that database by default, if the default database parameter was issued as part of sp_addlogin
Can use sp_modifylogin to make that database the default
This example shows how a Database Owner could give access permission to “maryh” of the engineering group “eng,” which already exists:
sp_adduser maryh, mary, eng
This example shows how to give “maryd” access to a database, keeping her name in the database the same as her login name:
sp_adduser maryd
This example shows how to add “maryj” to the existing “eng” group, keeping her name in the database the same as her login name by using null in place of a new user name:
sp_adduser maryj, null, eng
Users who have access to a database still need permissions to read data, modify data, and use certain commands. These permissions are granted with the grant and revoke commands, discussed in Chapter 12, “Managing User Permissions.”