MS SQL Server
  Home arrow MS SQL Server arrow Page 4 - Database Security in SQL Server 6.5
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MS SQL SERVER

Database Security in SQL Server 6.5
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 16
    2005-03-30

    Table of Contents:
  • Database Security in SQL Server 6.5
  • Aliasing Example
  • Database Groups
  • Managing Database Permissions
  • SETUSER
  • Working with Groups
  • Ownership Chains
  • Stored Procedures

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Database Security in SQL Server 6.5 - Managing Database Permissions


    (Page 4 of 8 )

    Once inside a database, SQL Server determines what a user (who is not an administrator) can do by looking at the list of object permissions assigned to the UID. SELECT, INSERT, UPDATE, DELETE, REFERENCE, and EXECUTE are object permissions that control what a user can do with tables, views, and stored procedures. Statement permissions control what objects the user can create, alter, or delete in the database.

    Permissions are represented by rows in the sysprotects system table, the structure of which is shown in Table 3-4.

    Table 3-4. The sysprotects System Table

    Column Data Type Description
    id int ID of object to which this permission applies.
    uid smallint ID of user or group to which this permission applies.
    action tinyint One of the following permissions:
    26 = REFERENCES
    193 = SELECT
    195 = INSERT
    196 = DELETE
    197 = UPDATE
    198 = CREATE TABLE
    203 = CREATE DATABASE
    207 = CREATE VIEW
    222 = CREATE PROCEDURE
    224 = EXECUTE
    228 = DUMP DATABASE
    233 = CREATE DEFAULT
    235 = DUMP TRANSACTION
    236 = CREATE RULE
    protecttype tinyint Either 205 (GRANT) or 206 (REVOKE).

    Table 3-4. The sysprotects System Table (continued)

    Column Data Type Description
    columns varbinary(32) Bitmap of columns to which this SELECT or UPDATE
    permission applies. Bit 0 indicates all columns; bit 1
    means permission applies to that column; NULL means
    no information.


    The first two columns are the same for most system tables that have an effect on database objects. The id column holds the object ID of the object for which you want to assign a permission. The uid column holds the UID for the user who will receive the permission. The next column, action, holds an 8-bit integer that describes the type of permission being assigned—you can see the types of permission listed in the table. The protecttype column holds a value of either 205 or 206 depending on whether the row describes a GRANT action or a REVOKE action. Finally, the columns column is a bitmap for column-level permissions, which I cover a little later.

    The key point to know about permissions is that they are represented by rows in sysprotects. If there is no row corresponding to the combination of the object and UID or the object and GID, the user has no permissions on the object. The only users that have permissions not reflected in sysprotects are sa, the database owner (dbo), and database object owners. Because sa has all database permissions, we will focus on dbo and object owners.

    The Database Owner

    The database owner, dbo, has special rights in the database that cannot be superseded or abridged by any other user. The only entity that has more rights on the server is sa. As you would expect, dbo only has rights within the database she owns; therefore, someone can be the database owner in one database and a regular user in another. Here is the list of permissions that only dbo has that cannot be granted to other database users:

    • CHECKPOINT

    • DBCC

    • DROP DATABASE

        •  GRANT and REVOKE statement permissions

        •  LOAD DATABASE

    • LOAD TRANSACTION

    • SETUSER

    dbo has built-in permission to run all statements and can grant some of those statement permissions to other database users. Here is the list of statement permissions that may be granted to other users:

    • CREATE DEFAULT

    • CREATE PROCEDURE

    • CREATE RULE

    • CREATE TABLE

    • CREATE VIEW

    • DUMP DATABASE

    • DUMP TRANSACTION

    Database Object Owner

    The purpose of granting permission to execute these statements is to allow other users to create objects in the database. Creating those objects grants the user special status as database object owner (dboo) for that particular object. Whereas there can be only one dbo, every user in the database may own one or more objects. Like dbo, dboo has special rights and privileges not shown in sysprotects.

    In particular, dboo has sole authority to decide what permissions on the object will be granted to other users. Only the object owner can use the GRANT and REVOKE commands for his object:

    GRANT {ALL | permission_list}
    ON {table_name [(column_list)] | view_name [(column_list)]
      |
        stored_procedure_name | extended_stored_procedure_name}
    TO {PUBLIC | name_list}
    REVOKE {ALL | permission_list}
    ON {table_name [(column_list)] | view_name [(column_list)]
      |
        stored_procedure_name | extended_stored_procedure_name} FROM {PUBLIC | name_list}


    NOTE  You can read more about the process of granting and revoking permissions in the section "The Art of Assigning Permissions" later in the chapter.

    Not even the dbo can assign permissions for objects he does not own, nor can he use another owner’s objects if the owner does not grant permission. Here is the list of permissions dboo receives for the object(s) he owns:

    • ALTER TABLE

    • CREATE INDEX

    • DROP INDEX

    • CREATE TRIGGER

    • DROP TRIGGER

    • DROP TABLE

    • TRUNCATE TABLE

    • UPDATE STATISTICS

        • GRANT and REVOKE (only on owned objects)


    NOTE  None of these permissions may be transferred to other users.

    This article is excerpted from SQL Server Security Distilled by Morris Lewis (Apress, 2004; ISBN 1590592190). Check it out at your favorite bookstore today. Buy this book now.

    More MS SQL Server Articles
    More By Apress Publishing


     

    MS SQL SERVER ARTICLES

    - Completing the Introduction to Transact-SQL
    - A Brief Introduction to Transact-SQL
    - Lookups and Blocking Bad Data
    - Field Validation Rules for Blocking Bad Data
    - Using Masks to Block Bad Data
    - Blocking Bad Data
    - Using @@ROWCOUNT and TABLE Variables for Dat...
    - How to Use Variables, IF and CASE in Databas...
    - Creating Important Aspects of Notification S...
    - Working wth Variables in Database Interactio...
    - Delving Deeper into Notification Services
    - Notification Services
    - Building a Multi-table Report with SQL 2005 ...
    - A Secure Way of Building Connection Strings
    - Transferring a Database Using the SSIS Desig...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT