Home > Articles > Data > SQL Server

Assigning Roles for Our Users in SQL Server 2000

Before you give users any access to your applications, you need to consider the roles that you want your users to have. In this excerpt from SQL Server 2000 Database Development From Scratch, author Rob Hawthorne discusses and defines SQL Server 2000's 10 basic database roles. These roles all allow for different levels of access to the database.
This article is excerpted from the author's book SQL Server 2000 Database Development From Scratch.
This chapter is from the book

Before we give our users any access to our application, we need to consider the roles that we want our users to have.

One Year "Roles" into the Next

So what is a role? Supposedly, roles came about in SQL Server 2000 when the Windows team suggested that they would change the name of the NT groups to roles. The SQL Server team thought they would be proactive and changed the name to agree with the changes that the Windows team was going to implement, but alas Windows 2000 was released with groups instead of roles. Aww well guys, there is always next year!

A role is similar in concept to the idea of a group in NT. We can assign permissions to either a role or an individual user. If we assign permissions to a role, then every user that we add to that role will inherit the permissions from the role.

Inherit is the capability of an object (in this case a user) to derive all the attributes from another object (in this case a role).

By default, SQL Server 2000 has 10 basic database roles defined. These roles all allow for different levels of access to the database.

There is one very special role, however: the Public role. Every single user who is defined within the database belongs to the Public role. The Public role has almost no permissions except the very basic ones that allow a user to make a connection to the database and so forth. This role has some basic rules around it.

  • It is contained within every database.

  • It cannot be dropped.

  • Every user belongs to the Public role, including the sa account.

  • Because every user belongs to the role by default, you cannot add or remove users from the role.

The permissions that the Public role has, as mentioned, are very limited. You can alter this, but buyers beware. Because every user belongs to the role, you might accidentally assign too much control to someone who does not know how to use it.

So what sort of permissions does each role have?

  • db_owner—This is the most God-like role that a user can have. This role allows a user complete control over the database. The sa user is a member of the dbo_owner role; hence the reason the sa account can do anything it wants to the database.

  • db_securityadmin— This role allows a user to manage all the roles and members of those roles. This role can also manage assigning permissions to the roles. If we had a user that we trusted to manage the security of our database but didn't need full control, we would assign them this role.

  • db_accessadmin—This role is used to give a user the rights to add or remove users within the database. As with our db_securityadmin role, we would normally grant the user this role as well to ensure that they can give users the necessary access they need.

  • db_ddladmin—This role allows a user to manipulate all the objects within the database. For example, a user can create, modify, or drop the database's objects. This role has permission to run all SQL Server 2000 DDLs.

  • db_backupoperator— This role allows the users assigned to the role to perform database backups.

  • db_datawriter—This role allows a user to modify the data in all the user tables defined within the database.

  • db_datareader—This role allows a user to view the data from all the user tables defined within the database.

  • db_denydatawriter—This role prevents a user from modifying any of the data in the user tables within the database.

  • db_denydatareader—This role prevents a user from viewing any of the data in the user tables within the database.

A user can belong to none, one, or many of these roles. If a user belongs to more than one role, the user will have the collective of all the permissions of the roles with respect to the rules of precedence.

For example, if our user, SQLSpyNetUser, belonged to the db_datawriter and the db_backupoperator roles, they would be able to not only modify data within a table, but also perform database backups.

However, if our SQLSpyNetUser user belonged to the db_denydatawriter and the db_datawriter roles, then our user wouldn't be able to update data within our tables. What? Why? Because denying access to a database is more restrictive than granting access, and denying access has a higher precedence than granting access.

So be careful when assigning roles to your users. You might accidentally restrict users from a table or other database object that they really need access to.

Assigning Roles to the SQL Server Instance

Not only can we assign roles for our users within our SQLSpyNet database, but we can also assign users roles for the whole SQL Server 2000 instance. This allows us greater flexibility in deployment, especially in a large site. This means that we can allow only certain people the rights to, for example, back up our database. With this we can then ensure that no one tries to perform a backup without fully understanding what he or she is doing!

So what are the server roles that SQL Server 2000 has available?

NOTE

You can view the server roles for your instance of SQL Server 2000 under Security, Server Roles. All the current server roles installed for your instance of SQL Server 2000 will be within the Server Roles folder.

  • sysadmin—This role has full control over the whole instance of SQL Server 2000. This is the role to which the sa account belongs.

  • securityadmin—This role can create and manage logins for the server.

  • serveradmin—This role can set the configuration options of the instance of SQL Server 2000. This role also has the ability to shut down the server.

  • setupadmin—This role has the ability to manage startup procedures and linked servers.

  • processadmin—This role has the ability to manage the processes that SQL Server 2000 has running. This means that this role can issue the KILL command, which finishes a user's session. If the user has any open transactions, their transaction is rolled back before the session is terminated.

  • diskadmin—This role can manage the files on disk, for example filegroups.

  • dbcreator—This role can create, alter, and drop databases.

NOTE

Most of these roles allow members of the role to add other users to the role. For example, if our SQLSpyNetUser belonged to the dbcreator role, he could then add any other users to the role.

NOTE

But be careful because not all roles allow the addition of new members to the role. For example, the db_datawriter role does not allow users to add new members to the role.

Okay, I know there are some actions that these roles perform that we haven't discussed yet, but hey, we will get there!

What happens when these roles do not really suit our business rules? Let's take a look at some options now.

Creating a Role Model

If I have 10 new users but am not really sure that I want to grant them as much access (or as little) as the built-in server/database roles provide, what can I do?

SQL Server 2000 allows us to create our own roles. If all of our users are to have similar access, the best idea is to create a role, add each user to the role, and then grant and deny the permissions on each object that they will be allowed to perform.

That sounds really cool! The perfect solution for my problem!

However, we currently have only one user. Is it really worth creating a whole role for just one user?

Well luckily for us, SQL Server 2000 allows us to grant/deny permissions on every object within the database to a single user/users. So, for example we might allow our SQLSpyNetUser to alter addresses in the Address table (SELECT, INSERT, UPDATE, and DELETE), but prevent them from altering any of the Spies details.

NOTE

This sort of flexibility is available to us within SQL Server 2000 (and in fact all previous versions), but SQL Server 2000 also allows us to prevent our SQLSpyNetUser from viewing the AnnualSalary column in the Spy table! We have that fine of granularity control over the permissions that our users have.

For us to leverage the best from our application, we are now going to create a role for our database and then assign our user accounts to the role. Our role will be assigned basic permissions that allow our users assigned to the role to perform some tasks against our database.

First let's create the database role.

  1. In Enterprise Manager, go to the SQLSpyNet database and then navigate your way to the Roles folder.

  2. When you are there, right-click and select New Database Role. This will give you a screen similar to that shown in Figure 1.

    Figure 1 Creating a new role for our SQLSpyNet database.

  3. Like most database objects, we need to give our role a name with which SQL Server 2000 can use to identify the object. Let's give our new role a name of SQLSpyNetRole. Once again you can name this anything you like, but it is better to use a descriptive name.

  4. Select Standard Role for the database role type, but notice that SQL Server offers these two roles:

    • Standard role—This type of role is generally similar to the groups in Windows NT. This role can contain users, and permissions can be applied. When a user connects (and they are a member of the role) they inherit the permissions of that role (as well as any other permissions the user might have).

    • Application role—These are special roles within SQL Server 2000 because they do not contain any members (or users). In some ways you can think of these special roles as user accounts. Application roles act like users because they require a password to be activated. However, when the role is activated (by supplying a password and using the sp_setapprole stored procedure), the connection loses all the permissions that the users, roles, and NT Groups have while the connection is active. It becomes the responsibility of the application to take over the task of user authentication, but because SQL Server 2000 must authenticate the application when it establishes a connection, the application must supply a password.

  5. The next thing that we need to do is add our SQLSpyNetUser to the role, so click the Add button and you will see a screen similar to that shown in Figure 2.

    Figure 2 Assigning our SQLSpyNetUser to the SQLSpyNetRole within Enterprise Manager.

  6. This screen contains a list of our current users in the database, but because we have only one, this is all that is shown! If you have more than one user, simply click the users you want to add.

And there we have it! Our user is now a member of the SQLSpyNetRole and will inherit all the rights that the role has (which are none at the moment!).

TIP

Do not close the Database Role Properties window just yet! You can launch the Permissions window from this one, and we are going to assign the permissions very soon!

Now let's have a go at granting our SQLSpyNetRole some basic permissions within the database. There are two ways to accomplish this task—either through code or through using the graphical tools in Enterprise Manager. This time, however, we are going to use the graphical tools in Enterprise Manager. I just heard you say, "Whew!"

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020