> If I want to model say a book where I have a root element of book represented as
> n pages, can I do something like this:
[quoted text clipped - 13 lines]
> can see that I would want to is if I want to have many different books but then
> I would have to have BOOK, and then a BOOK_PAGES joining table no?

Signature
(reverse (concatenate 'string "moc.enworbbc" "@" "enworbbc"))
http://www3.sympatico.ca/cbbrowne/postgresql.html
Lisp stoppped itself
FEP Command:
cbbrowne@acm.org says...
> You almost certainly should have a UNIQUE primary key on every relation.
Maybe this true in theory, but not essential in practice?
I'm not being facetious here.
Take an example that I recently worked on - we have a lookup table of 26
counties (in Ireland) which really has a very small about of data in it,
say max. 1.5K.
Now, as I understand it, RDBMS's will look at the size of a table before
scanning it to see if it's worthwhile using an index, and if the table
is too small, it'll just perform a straigh scan anyway and not bother
with the index, even if you've gone to the trouble of putting one in.
AFAIK, this is true for the RDBMS's that I use (Interbase, FireBird and
PostgreSQL).
Any thoughts, rants, references, URLs on this topic welcomed.
Paul...

Signature
plinehan__AT__yahoo__DOT__com
C++ Builder 5 SP1, Interbase 6.0.1.6 IBX 5.04
p.s. just lacerated a tendon in left hand, so pls
excuse typos and tricky abbrevs - TIA.
Shane Petroff - 23 Aug 2003 18:59 GMT
> cbbrowne@acm.org says...
>
[quoted text clipped - 5 lines]
>
> AFAIK, this is true for the RDBMS's that I use
As far as anyone can tell, this is only true for some subset of dbms's
right now. Whether it holds true for any dbms in general or any of the
aforementioned at some other time is impossible to say. The
implementation that some specific db uses at some point in time is
entirely irrelevant to the topic at hand. The existence of a primary key
is a topic related to the structure of the data, not an implementation
strategy in some specific dbms.
Shane
Venkat - 23 Aug 2003 19:28 GMT
"Paul" <paul@not.a.chance.ie> wrote in
> Take an example that I recently worked on - we have a lookup table of 26
> counties (in Ireland) which really has a very small about of data in it,
[quoted text clipped - 3 lines]
> is too small, it'll just perform a straigh scan anyway and not bother
> with the index, even if you've gone to the trouble of putting one in.
Paul,
You are confusing an index with a key. Index is physical, while a key is
logical. Not all keys need to have a related index. Even if the key has an
associated index, it need not be used in the queries. For example, some
RDBMSs don't create indexes (indices) for the foreign keys, while some of
them create the associated index automatically. In some RDBMSs, even the
unique indexes for the primary/unique key have to be explicitly created.
> AFAIK, this is true for the RDBMS's that I use (Interbase, FireBird and
> PostgreSQL).
>
> Any thoughts, rants, references, URLs on this topic welcomed.
Here is one URL that might be of use:
http://www.aisintl.com/case/relational_keys.html
> p.s. just lacerated a tendon in left hand, so pls
> excuse typos and tricky abbrevs - TIA.
Hope you get your tendon fixed soon.
-- Venkat
Pablo Sanchez - 23 Aug 2003 19:57 GMT
> Now, as I understand it, RDBMS's will look at the size of a table
> before scanning it to see if it's worthwhile using an index, and if
> the table is too small, it'll just perform a straigh scan anyway and
> not bother with the index, even if you've gone to the trouble of
> putting one in.
Aside what Venkat points out, the more complex the query (more tables
in the join) it's possible that the above becomes grossly
inefficient. In-memory table scans can be very costly when paired
with (millions of) nested iterations.

Signature
Pablo Sanchez, Blueoak Database Engineering
http://www.blueoakdb.com
Bob Badour - 24 Aug 2003 00:42 GMT
> cbbrowne@acm.org says...
>
[quoted text clipped - 15 lines]
> AFAIK, this is true for the RDBMS's that I use (Interbase, FireBird and
> PostgreSQL).
Uniqueness is a logical constraint independent of any physical structure
like an index. It is true that SQL generally confuses the two levels by
making uniqueness an attribute of an index.
Without any uniqueness, how do you plan to distinguish between rows?
Christopher Browne - 24 Aug 2003 04:09 GMT
Centuries ago, Nostradamus foresaw when Paul <paul@not.a.chance.ie> would write:
> cbbrowne@acm.org says...
>
[quoted text clipped - 3 lines]
>
> I'm not being facetious here.
Do you want counties to be unique?
If you do, then you need a UNIQUE key that will amount to providing a
PK.
> Now, as I understand it, RDBMS's will look at the size of a table
> before scanning it to see if it's worthwhile using an index, and if
> the table is too small, it'll just perform a straigh scan anyway and
> not bother with the index, even if you've gone to the trouble of
> putting one in.
Size is irrelevant to the matter.
The issue is of whether or not you want to use a relational database
to actually maintain some aspects of correctness.
If you don't care about correctness, then feel free to do whatever you
like.
I have seen database systems that accept invalid inputs, silently
transforming erroneous data into other erroneous data. (Indeed, that
is true for date handling for one of the most popular "open source"
database systems.) That doesn't give me any "warm fuzzies" about the
wisdom of using it to store data of any importance.
Having the UNIQUE index is a way of making sure that the data in the
database is CORRECT (or at least of preventing /some/ errors); I don't
give a rip whether the index is used for queries; the point of the
exercise is to keep from filling the database with garbage.
> AFAIK, this is true for the RDBMS's that I use (Interbase, FireBird
> and PostgreSQL).
You seem to be falling into the trap of becoming dependent on the
physical and/or logical representation of the data. Codd's principles
include that activities should remain unimpaired when changes are made
to physical and logical storage representations or access methods.
I could not care less whether or not the "region" index gets used to
access the data. The point of the index, in this case, is NOT to
improve access times, but rather to enforce uniqueness of the primary
key. What the query planner does or does not do is totally irrelevant
to that point.

Signature
let name="cbbrowne" and tld="ntlug.org" in name ^ "@" ^ tld;;
http://www3.sympatico.ca/cbbrowne/spreadsheets.html
"I'm sorry, the teleportation booth you have reached is not in service
at this time. Please hand-reassemble your molecules or call an
operator to help you...."
>In the case of your BOOK relation, it might make sense for the
>relation to look something like:
[quoted text clipped - 8 lines]
>alternatively use an internal identifier, and have the ISBN in a "book
>catalogue" table...)
To be pedantic (and I am replying to this in a theory newsgroup) you
should probably call this table Editions instead of Book. If you have
two books with the same ISBN they are instances of an edition. You would
expect two books with the same ISBN to have identical pagination.
If you want to distinguish between books which are copies of the same
edition you may have to introduce some other distinction.
Two that actually exist are the "state" and "printing."
If an edition of a book is printed and half the copies are bound in
yellow covers and half have green covers then whichever went on sale
first is the "first state." This can have make a factor of 10 difference
in their selling price.
Typically popular books are reprinted and these days the number of the
printing is recorded on the flyleaf. Successive printings may have the
same ISBN but collectors always want the first printing. The difference
in price between a first printing and a later one may be $30,000 so this
is something that a collectors' or sellers' database must record.

Signature
Bernard Peek
London, UK. DBA, Manager, Trainer & Author. Will work for money.