|
Posted by Daz on 10/25/06 02:25
Rik wrote:
> You don't seem to get it.
> Each user does NOT have one row per book. Each user has ONE row per book
> THAT HE OWNS.
>
> Table USERS:
> user_id PRIMARY(/UNIQUE)
> user_name etc....
>
> Table BOOKS
> book_id PRIMARY(/UNIQUE)
> book_title etc....
>
> Table USER_BOOKS
> user_id ---|
> |-> UNIQUE
> book_id ---|
>
> And those 2 id's there are combined unique, for the user will have only one
> copy of one book, or if he has several, add a field 'amount', and
> increment/decrement that as fit. A field does not have to be unique for
> such an index, a COMBINATION of fields (mostly one, but an arbitrary amount
> suffices) has to.
>
> Hopefully this way I have shed some light on the subject, I cannot tell you
> any clearer.
That's much clearer. Tahk you very much. I think I had misunderstood
the nature of UNIQUE indexes, and thought it meant that there could
only be one field in a column containing a particular value. What I was
missing was that I UNIQUE can work across columns. That's very good to
know. Sorry for wasting more of your time than you felt was necessary.
It was not in vein, and it's very much appreciated. :)
Sincerest regards.
Daz.
Navigation:
[Reply to this message]
|