|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
define tables
Hi,
An example: primary key(personId), unique id(personId),) I often see primary key and unique id go together when define a table in some articles. Why unique id(personId) is needed? Doesn't primary key is already unique? Thanks, John |
|
#2
|
|||
|
|||
|
Hi
actually any one field can be primary key and unique key but they have different meaning primary key is used in relations with other tables ( basically to link tables) unique key need not be a primary key it is used when you need some field to be unique but you dont want it to link to any table Hope this helps Cheers Jayesh Jain |
|
#3
|
|||
|
|||
|
Thanks, but why declare primary key and unique key for the same field?
|
|
#4
|
|||
|
|||
|
You dont have to, but older versions of MySQL don't like it when you don't call both. If your using a fairly recent version of MySQL you will only have to call:
primary key(personId), i would only define a unique key if i didnt want to have multiple records of something. Say you have a field called 'color' and you didnt want to have the same color listed twice, you would make the color field unique as JayeshJain said. |
|
#5
|
|||
|
|||
|
OH, that's why. Thanks Ben.
![]() |
![]() |
| Viewing: Dev Articles Community Forums > Databases > General SQL Development > define tables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|