11.1.4. SQL Statements for User Management

In Firebird 2.5 and above, user accounts are created, modified and deleted using a series of SQL statements that can be submitted by a user with full administrator rights in the security database.

For a Windows Administrator, AUTO ADMIN MAPPING enabled only in a regular database is not sufficient to permit management of other users. For instructions to enable it in the security database, see Auto Admin Mapping in the Security Database.

Non-privileged users can use only the ALTER USER statement and then only to edit some data in their own accounts.

CREATE USER

Used for

Creating a Firebird user account

Available in

DSQL

Syntax

  1. CREATE USER username PASSWORD 'password'
  2. [FIRSTNAME 'firstname']
  3. [MIDDLENAME 'middlename']
  4. [LASTNAME 'lastname']
  5. [GRANT ADMIN ROLE]
Table 178. CREATE USER Statement Parameters
ParameterDescription

username

User name. The maximum length is 31 characters, following the rules for Firebird regular identifiers. It is always case-insensitive

password

User password. Its theoretical limit is 31 bytes but only the first 8 characters are considered. Case-sensitive

firstname

Optional: User’s first name. Maximum length 31 characters

middlename

Optional: User’s middle name. Maximum length 31 characters

lastname

Optional: User’s last name. Maximum length 31 characters

Use a CREATE USER statement to create a new Firebird user account. The user must not already exist in the Firebird security database, or a primary key violation error message will be returned.

The username argument must follow the rules for Firebird regular identifiers: see Identifiers in the Structure chapter. User names are always case-insensitive. Supplying a user name enclosed in double quotes will not cause an exception: the quotes will be ignored. If a space is the only illegal character supplied, the user name will be truncated back to the first space character. Other illegal characters will cause an exception.

The PASSWORD clause specifies the user’s password. A password of more than eight characters is accepted with a warning but any surplus characters will be ignored.

The optional FIRSTNAME, MIDDLENAME and LASTNAME clauses can be used to specify additional user properties, such as the person’s first name, middle name and last name, respectively. They are just simple VARCHAR(31) fields and can be used to store anything you prefer.

If the GRANT ADMIN ROLE clause is specified, the new user account is created with the privileges of the RDB$ADMIN role in the security database (security2.fdb). It allows the new user to manage user accounts from any regular database he logs into, but it does not grant the user any special privileges on objects in those databases.

To create a user account, the current user must have administrator privileges in the security database. Administrator privileges only in regular databases are not sufficient.

CREATE/ALTER/DROP USER are DDL statements. Remember to COMMIT your work. In isql, the command SET AUTO ON will enable autocommit on DDL statements. In third-party tools and other user applications, this may not be the case.

Examples

  1. Creating a user with the username bigshot:

    1. CREATE USER bigshot PASSWORD 'buckshot';
  2. Creating the user john with additional properties (first and last names):

    1. CREATE USER john PASSWORD 'fYe_3Ksw'
    2. FIRSTNAME 'John'
    3. LASTNAME 'Doe';
  3. Creating the user superuser with user management privileges:

    1. CREATE USER superuser PASSWORD 'kMn8Kjh'
    2. GRANT ADMIN ROLE;

See also

ALTER USER, DROP USER

ALTER USER

Used for

Modifying a Firebird user account

Available in

DSQL

Syntax

  1. ALTER USER username [SET]
  2. [PASSWORD 'password']
  3. [FIRSTNAME 'firstname']
  4. [MIDDLENAME 'middlename']
  5. [LASTNAME 'lastname']
  6. [{GRANT | REVOKE} ADMIN ROLE]
Table 179. ALTER USER Statement Parameters
ParameterDescription

username

User name. Cannot be changed.

password

User password. Its theoretical limit is 31 bytes but only the first 8 characters are considered. Case-sensitive

firstname

Optional: User’s first name, or other optional text. Max. length is 31 characters

middlename

Optional: User’s middle name, or other optional text. Max. length is 31 characters

lastname

Optional: User’s last name, or other optional text. Max. length is 31 characters

Use an ALTER USER statement to edit the details in the named Firebird user account. To modify the account of another user, the current user must have administrator privileges in the security database. Administrator privileges only in regular databases are not sufficient.

Any user can alter his or her own account, except that only an administrator may use GRANT/REVOKE ADMIN ROLE.

All of the arguments are optional but at least one of them must be present:

  • The PASSWORD parameter is for specifying a new password for the user

  • FIRSTNAME, MIDDLENAME and LASTNAME allow updating of the optional user properties, such as the person’s first name, middle name and last name respectively

  • Including the clause GRANT ADMIN ROLE grants the user the privileges of the RDB$ADMIN role in the security database (security2.fdb), enabling him/her to manage the accounts of other users. It does not grant the user any special privileges in regular databases.

  • Including the clause REVOKE ADMIN ROLE removes the user’s administrator in the security database which, once the transaction is committed, will deny that user the ability to alter any user account except his or her own

Remember to commit your work if you are working in an application that does not auto-commit DDL.

Examples

  1. Changing the password for the user bobby and granting him user management privileges:

    1. ALTER USER bobby PASSWORD '67-UiT_G8'
    2. GRANT ADMIN ROLE;
  2. Editing the optional properties (the first and last names) of the user dan:

    1. ALTER USER dan
    2. FIRSTNAME 'No_Jack'
    3. LASTNAME 'Kennedy';
  3. Revoking user management privileges from user dumbbell:

    1. ALTER USER dumbbell
    2. DROP ADMIN ROLE;

See also

CREATE USER, DROP USER

DROP USER

Used for

Deleting a Firebird user account

Available in

DSQL

Syntax

  1. DROP USER username
Table 180. DROP USER Statement Parameter
ParameterDescription

username

User name

Use the statement DROP USER to delete a Firebird user account. The current user requires administrator privileges.

Remember to commit your work if you are working in an application that does not auto-commit DDL.

Example

Deleting the user bobby:

  1. DROP USER bobby;

See also

CREATE USER, ALTER USER