SQL Server has a long list of roles for server, database, and applications that outline things like permissions, data selection and modification, and disk management. Examine how roles play a part in keeping SQL Server secure.
Most SQL Server databases have a number of users viewing and accessing data, which makes security a major concern for the administrator. The smart administrator will take full advantage of SQL Server security roles, which grant and deny permissions to groups of users, greatly reducing the security workload.
The first step in protecting your client’s data is determining which users need to view which data and then allowing access to only those users. For example, a payroll clerk probably views salary figures for everyone in your company while team managers have access to salaries for team members. Individual employees have no need to view salaries at all.
You must also decide which users can change the data. For example, although someone in fulfillment might need to verify a customer’s address, you may want only an account executive or a specially trained data entry clerk to change that account’s address.
Accommodating a number of users could be a huge task if it weren’t for the Windows security model, which can easily accommodate many users with one role. A role defines what a user can and can’t do within a database, and multiple users can share the same role. I’ll discuss roles and their relationship to Windows groups and show you how a role can grant or deny access to multiple users at the same time.
The benefits of using roles
Roles are a part of the tiered security model:
First, the user must log in to the server by entering a password. Once connected to the server, access to the stored databases is determined by user accounts. After gaining access to an actual database, the user is restricted to the data he or she can view and modify.
The main benefit of roles is efficient management. Imagine a group of 1,000 users suddenly needing to view or modify new data. Using Windows security, you simply select an existing Windows group and assign it to a SQL Server role—instead of modifying 1,000 user accounts. To clarify, Windows groups consist of users with access to the Windows network, but SQL Server roles belong strictly to SQL Server. You’re simply granting permissions to SQL Server data and objects to valid Windows users.
Role types
Server roles are maintained by the database administrator (DBA) and apply to the entire server, not an individual database file. The public role sets the basic default permissions for all users. Every user that’s added to SQL Server is automatically assigned to the public role—you don’t need to do anything. Database roles are applied to an individual database.
Predefined database roles
You may need to create your own, but you have access to several predefined database roles:
Fixed roles
The fixed server roles are applied serverwide, and there are several predefined server roles:
Assigning roles
Let’s use SQL Server Enterprise Manager to add a Windows group to a Pubs database (a sample database that comes with SQL Server 2000) role. The first step is to create a login for the members of the Guests group, so they can access SQL Server. To do so:
| Figure A |
![]() |
| We’ll add a new login to the SQL Server. |
| Figure B |
![]() |
| Choose the Guests group. |
| Figure C |
![]() |
| Select the Pubs SQL Server sample database. |
An alternate method for assigning a predefined role
You could’ve added the Guests group to any of the listed roles for the Pubs database in the last section. In this section, I’ll show you an alternate method—adding the Guests group to the db_accessadmin role within the Pubs database. To do so:
| Figure E |
![]() |
| Choose the Guest login. |
| Figure F |
![]() |
| We added the Guest group to the db_accessadmin role. |
At this point, you’ve added the Windows Guest group to the SQL Server login and assigned the Guest group to the Pubs database db_accessadmin role. Members of the Guest group will now inherit the permissions in the db_accessadmin role (which are listed above) within the Pubs database.
Creating a new database role
The predefined roles, such as db_accessadmin, won’t always be adequate, but you can create new roles. Let’s add a new role named Purchasing:
| Figure G |
![]() |
| Create a new role named Purchasing. |
After creating the new Purchasing role for the Pubs database, you must define what the users assigned to the Purchasing role (via the Guest group) can do in the Pubs database. At this point, let’s set a few permissions for the new Purchasing role:
| Figure H |
![]() |
| Add DELETE permissions to the Purchasing role. |
Server roles
Server roles reach far (see the above list) and, as a general rule, you probably won’t assign users to any of the server roles.Use discretion when assigning server roles because they apply to the entire SQL Server instance, not just individual databases. Server roles are usually reserved for database and server administrators.
You can assign users to a server role in two ways: using the Enterprise Manager or the Query Analyzer.To add the Guest account to the Database Creators server role using Enterprise Manager:
| Figure I |
![]() |
| Add Guest to the Database Creators server role. |
To use the Query Analyzer, run the following system stored procedure, where name identifies the user and role is one of the roles listed above:
Exec sp_addserverrolemember name, role
For instance, the following statement would add Martin Reid to the SysAdmin role:
Exec sp_addserverrolemember “Martin Reid”, “SysAdmin”
Not exactly child’s play
Data is an asset—it has monetary value to most companies and must be protected.Windows Authentication simplifies the process of adding roles to your SQL Server databases. It’s not kid’s play, but Windows can assist you in managing an instance of SQL Server. Familiarize yourself with SQL Server and Windows security before you try to put roles to work.
SQL Server comes with stored procedures that can assist you in managing areas of the server. A full list of procedures can be viewed at Microsoft’s MSDN site.