Re: does a table always need a PK?

From: Jerry Gitomer <jgitomer_at_erols.com>
Date: Fri, 22 Aug 2003 18:18:46 -0400
Message-ID: <bi64re$4cq$1_at_bob.news.rcn.net>


etp wrote:

> 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:
>
> table BOOK
> -----------------------------
> pageid FK
>
> and
>
> table PAGES
> -----------------------------
> pageid PK
> content text
>
> i.e do I need to have a (f.e.) primary key in the BOOK table?
> The only reason I 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?
>
> Danke!
>
> -Tomas
>
> ,%%%,
> ,%%%` %==--
> ,%%`( '|
> ,%%_at_ /\_/
> ,%.-"""--%%% "_at_@__
> %%/ |__`\
> .%'\ | \ / //
> ,%' > .'----\ | [/
> < <<` ||
> `\\\ ||
> )\\ )\
>

^^^^^^^^"""^^^^^^""^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> THE DUKE
As long as you only have one book you have no need for a primary key ;-) You should always have a primary key. In fact many DBMS require one.

You do not need a BOOK_PAGES joining table. You could add a column for BOOK_ID to your PAGES table.

-- 
Once I learned how to spell DBA I became one -- Jerry Gitomer
Received on Sat Aug 23 2003 - 00:18:46 CEST

Original text of this message