Beginning SQL

Beginning SQL Beginning SQL

marjan.fesb.hr
from marjan.fesb.hr More from this publisher
20.07.2013 Views

Chapter 12 Privileges Privileges are the ability to perform some action on some object. The SQL1 standard defines only privileges on tables and views and thus defines only four basic privileges that work on these objects: ❑ The SELECT privilege allows the user to create data sets of columns and rows from tables or views. With this privilege, the user can specify a view or table name in the FROM clause of a SELECT query. The SELECT privilege means that the user is allowed to view or use data from the table or view on which the SELECT privilege is granted. ❑ The INSERT privilege allows the user to insert new rows into the table or view on which the INSERT privilege is granted; thus they can use that table or view name in the INTO clause of an INSERT statement. ❑ The DELETE privilege allows the user to delete rows from the table or view on which the DELETE privilege is granted; thus they can use the name of that table or view in the FROM clause of a DELETE statement. ❑ The UPDATE privilege allows the user to update rows from the table or view on which the DELETE privilege is granted; thus they can use the name of that table or view in the UPDATE statement. These four privileges are all that the SQL1 standard allowed, and these privileges are implemented in all commercial SQL-compliant DBMSs. Extended Privileges 336 SQL2 expanded on the concepts of SQL1 in several ways. First, it added the ability to the INSERT and UPDATE statements to operate on specific columns instead of on the entire table. Suppose that a new vice president is hired. The Personnel department is tasked with setting up all new personnel records, entering the name, address, personnel ID, and so forth. The salary and compensation information is not their department, however, and they should not have access to this information. Only the personnel manager is allowed to edit these fields. In SQL1, in order to get this capability, you had to implement views that retrieved the columns of interest and then use those views in an INSERT or UPDATE statement. Although this works, it leads to dozens of views whose sole purpose is to enforce security and makes administering security unnecessarily complex. In SQL2, however, you can directly create INSERT statements that insert only specific columns of the new record and then UPDATE statements that allow other users to update the columns for which they are responsible. Unfortunately, the SQL2 standard does not allow the SELECT statement to specify only selected columns, so for these statements you are back to creating views that pull specific columns and use them instead of a SELECT statement on the table directly. Many of the major DBMSs allow applying privileges to columns as an extension to the SQL2 syntax, using the same syntax as is used in the INSERT and UPDATE statements. In addition to the new column-specific privileges, the SQL2 standard adds the REFERENCES privilege, which addresses some rather subtle issues dealing with using foreign keys and check constraints. The issue here is that by including valid foreign keys in a SQL statement, a user can determine whether the key is valid or not, even if they are not supposed to have any access to the table from which the foreign key comes. An INSERT statement can be constructed that successfully inserts a record. Then the foreign key is added as a column to the statement. If a statement succeeds, the key is valid; if the statement fails, then the key is not valid. Suppose that the foreign key was the social security number (SSN) of an employee. The user would now be able to determine whether an employee existed with that SSN even though they are not supposed to be able to see the SSNs of the Employee table. Likewise,

Chapter 12<br />

Privileges<br />

Privileges are the ability to perform some action on some object. The <strong>SQL</strong>1 standard defines only privileges<br />

on tables and views and thus defines only four basic privileges that work on these objects:<br />

❑ The SELECT privilege allows the user to create data sets of columns and rows from tables or<br />

views. With this privilege, the user can specify a view or table name in the FROM clause of a<br />

SELECT query. The SELECT privilege means that the user is allowed to view or use data from<br />

the table or view on which the SELECT privilege is granted.<br />

❑ The INSERT privilege allows the user to insert new rows into the table or view on which the<br />

INSERT privilege is granted; thus they can use that table or view name in the INTO clause of an<br />

INSERT statement.<br />

❑ The DELETE privilege allows the user to delete rows from the table or view on which the DELETE<br />

privilege is granted; thus they can use the name of that table or view in the FROM clause of a<br />

DELETE statement.<br />

❑ The UPDATE privilege allows the user to update rows from the table or view on which the DELETE<br />

privilege is granted; thus they can use the name of that table or view in the UPDATE statement.<br />

These four privileges are all that the <strong>SQL</strong>1 standard allowed, and these privileges are implemented in all<br />

commercial <strong>SQL</strong>-compliant DBMSs.<br />

Extended Privileges<br />

336<br />

<strong>SQL</strong>2 expanded on the concepts of <strong>SQL</strong>1 in several ways. First, it added the ability to the INSERT and<br />

UPDATE statements to operate on specific columns instead of on the entire table. Suppose that a new vice<br />

president is hired. The Personnel department is tasked with setting up all new personnel records, entering<br />

the name, address, personnel ID, and so forth. The salary and compensation information is not their<br />

department, however, and they should not have access to this information. Only the personnel manager<br />

is allowed to edit these fields. In <strong>SQL</strong>1, in order to get this capability, you had to implement views that<br />

retrieved the columns of interest and then use those views in an INSERT or UPDATE statement. Although<br />

this works, it leads to dozens of views whose sole purpose is to enforce security and makes administering<br />

security unnecessarily complex. In <strong>SQL</strong>2, however, you can directly create INSERT statements that<br />

insert only specific columns of the new record and then UPDATE statements that allow other users to<br />

update the columns for which they are responsible.<br />

Unfortunately, the <strong>SQL</strong>2 standard does not allow the SELECT statement to specify only selected columns,<br />

so for these statements you are back to creating views that pull specific columns and use them instead of a<br />

SELECT statement on the table directly. Many of the major DBMSs allow applying privileges to columns as<br />

an extension to the <strong>SQL</strong>2 syntax, using the same syntax as is used in the INSERT and UPDATE statements.<br />

In addition to the new column-specific privileges, the <strong>SQL</strong>2 standard adds the REFERENCES privilege,<br />

which addresses some rather subtle issues dealing with using foreign keys and check constraints. The<br />

issue here is that by including valid foreign keys in a <strong>SQL</strong> statement, a user can determine whether<br />

the key is valid or not, even if they are not supposed to have any access to the table from which the foreign<br />

key comes. An INSERT statement can be constructed that successfully inserts a record. Then the<br />

foreign key is added as a column to the statement. If a statement succeeds, the key is valid; if the statement<br />

fails, then the key is not valid. Suppose that the foreign key was the social security number (SSN)<br />

of an employee. The user would now be able to determine whether an employee existed with that<br />

SSN even though they are not supposed to be able to see the SSNs of the Employee table. Likewise,

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

Saved successfully!

Ooh no, something went wrong!