Path: dp-news.maxwell.syr.edu!spool.maxwell.syr.edu!drn.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!news.mailgate.org!newsfeed.stueberl.de!npeer.de.kpn-eurorings.net!rz.uni-karlsruhe.de!inka.de!not-for-mail
From: "Felix E. Klee" <felix.klee@inka.de>
Newsgroups: comp.databases.theory
Subject: Re: How to ensure data consistency?
Date: Thu, 9 Sep 2004 01:46:28 +0200
Organization: (Posted via) INKA e.V. http://www.inka.de/
Lines: 42
Message-ID: <20040909014628.2dd3875d.felix.klee@inka.de>
References: <3lmnj0tdqs6n98so05hslbs6b0rjqkkdk7@4ax.com>
 <fo-dnaxhxYtECabcRVn-uA@comcast.com>
 <7dhqj057v2nb3jvgig151psbhl1mg9hrsm@4ax.com>
 <PP-dnUj6cu9gX6HcRVn-oQ@comcast.com>
 <3fsrj0lpe76pfvfjfe1ur2ubpb3hqu69fg@4ax.com>
 <20040907154957.697949a1.felix.klee@inka.de>
 <h98tj0p6bo8e15h4dmsbn68cul78u2ldjr@4ax.com>
 <20040907235658.3ae1b57a.felix.klee@inka.de>
 <46auj05c5ia04turqujjjm7rq97jn3d30c@4ax.com>
NNTP-Posting-Host: puric.inka.de
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
X-Trace: sapa.inka.de 1094687448 17326 193.197.184.17 (8 Sep 2004 23:50:48 GMT)
X-Complaints-To: abuse@inka.de
NNTP-Posting-Date: 8 Sep 2004 23:50:48 GMT
X-Newsreader: Sylpheed version 0.9.9 (GTK+ 1.2.10; i486-slackware-linux-gnu)
Xref: dp-news.maxwell.syr.edu comp.databases.theory:25876

On Wed, 08 Sep 2004 09:03:30 -0700 ddtl wrote:
> >> If that is so, it won't work (try it!).
> >
> >I just tried it: It seems to work (didn't try implementing any checks,
> >though). What makes you believe that it doesn't?
> 
> I just wonder how new rows are going to be added to the main table - 
> before you can insert anything into it, you have to fill in data into
> the seconday tables (otherwise, if they are empty, FK constraints in the
> main table will prevent adding rows, because FK fields have to reference
> an already existing data). 

Yes, the row for the secondary table has to be filled in before entering
the corresponding row to the main table.

> Suppose you did just that, and want to insert the first item into the
> main table, and suppose that thit item belongs to a group 'b'. You
> fill in item's properties, and set b_id to one of the values in
> BS.b_id. But what do you do with TS.a_id, TS.c_id .... TS.N_id?

I set them to NULL and I don't see why this should be a problem. That
TS.b_id is non null can be validated using a CHECK similar to the
following (proposed by Tony somewhere in this thread):

CHECK ((type = 'A' AND a_id IS NOT NULL) OR (type != 'A' AND a_id IS
NULL))

> Besides, the same problem with the data integrity exists here - how can you
> ensure that the user, after inserting a new row into a sub-table, will update
> the main table accordingly?

To avoid orphaned rows in subtables, it seems necessary to set up
circular foreign key constraints.

Anyways, the above solution seems to be inferior to that proposed by
Lennart (in this thread) and that by Joe Celko [1] (that's the one that
Dan referred to, I guess). So further discussion of my proposal is not
necessary, IMO.

Felix

[1] http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=OEYKH2bbEHA.368%40TK2MSFTNGP10.phx.gbl&rnum=5
