20.07.2013 Views

Beginning SQL

Beginning SQL

Beginning SQL

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 12<br />

Another shortcut, using the PUBLIC keyword, grants privileges to all users:<br />

GRANT SELECT<br />

ON tblHolidays<br />

TO PUBLIC<br />

Using the PUBLIC keyword has the advantage of not having to explicitly grant privileges to users, since<br />

any current or even future authorized users are automatically in the listed privilege.<br />

Try It Out Using the GRANT Statement<br />

The GRANT statement creates an entry in the security system that allows a user in the current database to<br />

work with data in the current database or execute specific Transact-<strong>SQL</strong> statements.<br />

In the <strong>SQL</strong> window, type the following statement:<br />

GRANT SELECT, INSERT, UPDATE<br />

ON Attendance<br />

TO DataEntry<br />

GO<br />

GRANT SELECT<br />

ON Attendance<br />

TO Management<br />

GO<br />

How It Works<br />

Once the role is created, members are added to the role. This step allows members to inherit privileges<br />

for the roles that they play in the database. By running a GRANT statement on a given table or object, you<br />

assign specific privileges to that group (role in <strong>SQL</strong> Server) or user for that specific object. In this case,<br />

you have granted SELECT, INSERT, and UPDATE privileges to the DataEntry group, and you have<br />

granted only SELECT privileges to the Management group.<br />

Columns<br />

342<br />

The <strong>SQL</strong>1 standard allowed GRANT UPDATE privilege on individual columns of a table or view, while the<br />

<strong>SQL</strong>2 standard expanded that to include INSERT and REFERENCES privileges. The syntax lists the<br />

columns after the PRIVILEGE keyword, and they must be between parentheses and comma-delimited<br />

(separated by commas) if there are more than one. As an example, to give shipping personnel privileges<br />

to specific columns in the order item table, you could write a GRANT statement similar to the following:<br />

GRANT UPDATE (ShipDate, Quantity)<br />

ON tblOrderItem<br />

TO usrShipping<br />

As you have already seen, the <strong>SQL</strong> standard does not permit a column list for a SELECT privilege. The<br />

SELECT privilege must apply to all columns of the table or view. The normal method of handling this<br />

restriction is simply to create a view of the desired columns and then grant a SELECT privilege on the<br />

view. Of course, this forces you to design views that wouldn’t be necessary if a column list were allowed.<br />

For this reason, many of the DBMSs provide extensions to the standard to allow column lists in the<br />

SELECT grant statements. These extensions allow you to write statements like this:

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

Saved successfully!

Ooh no, something went wrong!