Re: Delete row in a lookup table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, August 18, 2007 6:31 pm, nitrox . wrote:
> Is it not considered good practice to have a primary key on a lookup
> table for a database?
> I have 3 tables setup, games, memberleagues and members. The
> memberleagues table holds the id of the games table and members table.
> The problem I have is that Im not sure how to delete a row from the
> memberleagues table without a primary key. If its not considered bad
> practice I could add a primary key to the memberleagues table and be
> done. Anybody have any tutorials on how to write the php for this?

You can add the primary key, no problem.

However, it might be kind of silly...

For a lookup table, you probably have:

member_id   |    game_id
------------------------
1           | 1
1           | 3
1           | 17
2           | 1
2           | 5
.
.
.


USUALLY you can just have the unique key be the composite key of
member_id, game_id and you just delete "where member_id = $m and
game_id = $g"

The data itself is the key, so to speak, because there can only be one
of each member/game combo, and it's unique all by itself.

Using an extra field for a key is only a "problem" if you have a
zillion members/games to the point where the "extra" space matters on
your hard drive.  In this day and age, you'd have to have a LOT of
members and games for an INT or even BIGINT to make that much
difference on the hard drive.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux