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 10<br />

Figure 10-7<br />

Summary views actually perform various operations on entire sets of rows, returning a single row representing<br />

some operation on the set. These views are never updateable.<br />

Notice that because MemberAttendance does all the grunt work of joining tables, such as aliasing field<br />

names, and so on, you can concentrate on the work you want to get done, filtering out a small set of<br />

fields from a small set of records. You no longer need to worry about what fields to join or look at ID<br />

field data (although the primary keys might be useful for joins further up the line).<br />

Updating Views<br />

294<br />

If you need to update data through your views, as opposed to simply reporting data sets, things can get<br />

a little trickier. A variety of things can cause a view to become non-updateable. Begin with what can be<br />

updated.<br />

Suppose you need to update member addresses from a sign-up list passed around during a meeting. The<br />

following view simply pulls records from the MemberDetails table.<br />

CREATE VIEW MemberUpdate<br />

AS<br />

SELECT FirstName, LastName, DateOfBirth, Street, State, City, ZipCode, Email,<br />

DateOfJoining<br />

FROM MemberDetails<br />

The preceding CREATE VIEW statement provides the results shown in Figure 10-8.<br />

Figure 10-8<br />

You can expect to edit the records, add new records, or delete existing records because it is straightforward<br />

for the DBMS to translate this request and figure out where the data came from and which table and fields<br />

need to be updated.<br />

In general, you can expect to be able to update most views against a single table, whether the entire row<br />

or just a few fields. These views can always be traced back to specific rows or columns in real tables, and<br />

there will almost never be a problem with these updates. The view may not be possible, however, if the<br />

view contains calculated fields. Many DBMSs allow this operation as long as you do not attempt an<br />

update to the calculated field itself.

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

Saved successfully!

Ooh no, something went wrong!