Reply to Re: A Question of design.

Your name:

Reply:


Posted by Rik on 10/25/06 00:38

Daz wrote:
> Rik wrote:
>> I have told you several times an index on 2 columns is perfectly
>> possible. Make the index:
>> ALTER TABLE `user_books` ADD UNIQUE (
>> `user_id` ,
>> `book_id`
>> )
>>
>> Voilα.
>
> Hi Rick. Sorry, I believe that I have also mentioned several times
> that
> I can't, as each user has one row per book, meaning there won't be any
> unique uids, and if there were, it wouldn't be for very long at all.
> The book_ids in the user table will also be duplicated, as more than
> one user is likely to have the same book.

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.
--
Grtz,

Rik Wasmus

[Back to original message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация