Re: is pivoted phones view updateable?
Date: 10 Nov 2006 10:26:36 -0800
Message-ID: <1163183196.730989.262270_at_m73g2000cwd.googlegroups.com>
Aloha Kakuikanu wrote:
> Tchuzhie Giri wrote:
> > It is not "OK" so long as one does not have your rules of updatability.
> > You put a pile of symbols on the pile of symbols: it does not have
> > sense without the rules. Please provide the rules, simple examples
> > and then one can go to more complex examples.
>
> Given two relation variables
>
> Y(n, #) -- aka WorkPhones(name, number)
> and
> Z(n, #) -- aka CellPhones(name, number)
>
> and two relation constants
>
> A = {(t='work')}
>
> and
>
> B = {(t='cell')}
>
> is the view
>
> X = (Y /\ A) \/ (Z /\ B) -- aka ConsolidatedPhones
>
> updateable? There is no minus operator involved. The only two RA
> operators are join /\ and union \/.
When writing an article about view updates, found some old (Nov 2000) unpublished article about view updates. Here it goes:
Database View Updates
Introduction.
Relational databases live longer than applications that use them. In a long database lifetime its schema inevitably changes. Those changes often break existing applications unless application developers provide some kind of logical data independence. Using PL/SQL packages as an interface to the database data became ubiquitous approach in today's practice.
Database Views is an alternative way to achieve logical data independence. In theory, database views are superior to any procedural solution (such as PL/SQL package interfaces), because views have fundamental relational closure property. This statement, however, is seriously undermined by existing limitations on view updates.
Let reader not to receive a false impression that this is pretty abstract subject interesting to experts only. The article goes through an example of schema change that author found repeating over and over again during his work at several application development projects. And the purpose of this whole exercise is to show how to use views such that the reader would be saved of writing tedious mechanical procedural code.
Schema evolution example
During database lifetime its schema encounters several growth and restructuring changes:
· Expansion of a table to include new column, or modifications of existing column datatypes.
· The inclusion of a new table. · Restructuring that, although preserves overall information, changesthe placement of the data.
Table restructuring is a main theme of this article. In a typical
example the table
TABLE contact (
id NUMBER, voice VARCHAR2(10), fax VARCHAR2(10)
);
might require additional cellular column. Instead of growing the table, however, it is better to reorganize it like this:
CREATE TABLE newcontact (
id NUMBER, phonetype VARCHAR2(5), number VARCHAR2(10)
);
Each record in the old contact table
ID VOICE FAX 1 4150000000 4081111111 2 80012345672 6501234567
is equivalent to 2 records in the newcontact table
ID PHONETYPE NUMBER 1 VOICE 4150000000 1 FAX 4081111111 2 VOICE 8001234567 2 FAX 6501234567
Clearly, if we simply drop the old table and naively assign contact name to the new table it would break existing applications. Let's take a look how we can handle this problem.
Mapping View
The view
CREATE VIEW oldcontactview AS
select a.id, a.number voice, b.number fax
from newcontact a, newcontact b
where a.id = b.id
and a.phonetype = 'VOICE'
and b.phonetype = 'FAX';
Some historical background
"An Introduction to Database System" by C.J. Date has an inspiring chapter on view updates with bibliography. Not surprisingly, author proposes his solution to update view problem as well. He revised it in his latest "Relational Database Writings" series of papers, but his approach is inherently case-by-case analysis. It is a matter of believe, of course, whether case-by-case approach is fitting well into Relational Theory
Author discovered the inverse and direct views while working on one of application integration projects. Unfortunately, today's reality is that application integration engineers community tend to think in API, Messages, XML and many other categories rather than views. Ironically, it seems to require certain level of sophistication to appreciate elegance and simplicity of views.
Conclusion
This article goes only as far as claiming that if inverse view exists then direct view is modifiable. Writing reverse view declaration is still database programmer's responsibility. Which approach is better: writing "INSTEAD OF" trigger, or writing inverse view is a matter of preference declarative SQL style over procedural programming.
An open question remains if it's possible to automatically deduce inverse view from direct view. The fact, though, that general view update problem is hard, indicates that there likely to be no easy answer. Received on Fri Nov 10 2006 - 19:26:36 CET