20.07.2013 Views

Beginning SQL

Beginning SQL

Beginning SQL

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

check constraints can be used in a similar manner. Because check constraints do not expose data to viewing,<br />

update, and deletion, they are often treated differently by the DBMS when it comes to security.<br />

Thus, a user could include tables and fields in a check constraint to which he otherwise wouldn’t have<br />

access. This opens up a similar security hole in that a user could try different values in a check constraint<br />

to discover the values of a field that he isn’t supposed to be able to see.<br />

To eliminate this hole in security, the REFERENCES keyword was added. The REFERENCES privilege is<br />

assigned to specific rows of tables. Unless assigned a REFERENCES privilege, a user cannot reference that<br />

column in that table in any manner.<br />

The USAGE Privilege<br />

The USAGE privilege is used to control access to domains, or the sets of legal values in a given column, as<br />

well as user-defined character sets, translations, and collating sequences. USAGE is a simple true/false<br />

property that says a user has access to one of these objects for individual user ID. This privilege is aimed<br />

at the corporate developer more than the individual database user.<br />

Ownership<br />

When you create a table in <strong>SQL</strong> using the CREATE TABLE statement, you become the owner of that table<br />

and control security on that table. You have full privileges for SELECT, INSERT, DELETE, and UPDATE for<br />

that table. You also are able to grant privileges to that table to other user IDs. In fact, other users have no<br />

privileges on that table until you specifically grant those privileges to those users.<br />

The situation for views is a little different, however. In order to create a view, you must have specific<br />

privileges on the table or tables from which you pull data. You must at least have SELECT privileges to<br />

the underlying tables. Thus, the DBMS automatically gives you SELECT privileges to the resulting view.<br />

The other privileges (INSERT, DELETE, and UPDATE) depend on your privileges in the underlying tables<br />

for the view, and you must have each privilege for every table in the view before you are granted that<br />

privilege in the resulting view. Furthermore, you can grant privileges to other user IDs for the view only<br />

if you have been granted the privilege to grant those privileges. You learn about granting privileges in a<br />

later section of this chapter, but first you learn more about the relationship between views and security.<br />

Views and Security<br />

Views are often used to enforce security on viewing data. By creating views that display specific columns<br />

from specific tables, a user can be granted SELECT privileges for that view but not for the underlying<br />

table. Using this strategy makes it possible to determine exactly what information a specific user is<br />

allowed to view.<br />

Vertical and Horizontal Views<br />

Vertical views represent select columns of one or more tables such that the user can see only portions of a<br />

table or tables. This allows you to hide sensitive data columns from certain users while allowing access<br />

to those columns to other users.<br />

For example, suppose you had a business rule that states that employees in the Personnel department<br />

should be able to see the names and addresses of all employees, but not the SSN or salary. You might<br />

implement this view with a <strong>SQL</strong> statement similar to the following:<br />

CREATE VIEW vEmployeeNonSensitive AS<br />

SELECT Name, Address, City, State, ZIP, Phone FROM tblEmployees<br />

<strong>SQL</strong> Security<br />

337

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!