If you are using AID (article ID) and PID (page id) would both of these have to be the primary key?
Printable View
If you are using AID (article ID) and PID (page id) would both of these have to be the primary key?
No. Only one of those columns would get the primary key.
Actually, a primary key isn't even required, it only speeds up searching the database.
And you can have only 1 primary key! you can have several unique keys though.
In the tutorial offered by sitepoint he uses two primary keys at one point.
I tried using two and it works.
I asked becasue, There would be multiple of PID and AID everywhere, so making both primary says that both must be unique as if they were one
2 Primary keys in the same table??
Well as you were obviously wrong :D I guessed I would proove it.....
open MySQL...
Apache...
phpMyAdmin...
type type...
ah!.... MySQL will let you have 2 primaries!
So I take it all back ! (again!)
hmmmmmmm...
I'll just clear this one up MySQL does not allow two primary keys in the same table. What it does allow is for you to specift 1 or more columns to be used as a compound primary key which it what you are all getting confused with.
If you specify aid and pid as a compound key then all combinations of aid and pid will be unique.
Thanx