|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
PRIMARY KEY: INT v. VARCHAR(255)
I've got the following design:
Code:
CREATE TABLE a( aId INT NOT NULL, aValue VARCHAR(255) NOT NULL, PRIMARY KEY (aId), UNIQUE (aValue) ) TYPE=InnoDB; CREATE TABLE b( ... aId INT NOT NULL, ... FOREIGN KEY aId REFERENCES a (aId), ... ) TYPE=InnoDB; Is my design (above) prefered to the following: Code:
CREATE TABLE a( aValue VARCHAR(255) NOT NULL, PRIMARY KEY (aValue), ) TYPE=InnoDB; CREATE TABLE b( ... aValue VARCHAR(255) NOT NULL, ... FOREIGN KEY aValue REFERENCES a (aValue), ... ) TYPE=InnoDB; In other words: is using an INT PRIMARY KEY prefered to using a VARCHAR PRIMARY KEY. In what cases should a VARCHAR (if ever) PRIMARY KEY be used?? Cheers, Ben |
|
#2
|
||||
|
||||
|
I depends on what it is that you are storing in the varchar field. It was discussed here recently (and concluded) that the most appropriate key is simply a meaningless, incrememting number - http://forums.devarticles.com/t8658/s.html
|
|
#3
|
|||
|
|||
|
Quote:
I read the article - and it appears there are very mixed views! Does a VARCHAR affect the performance in anyway? (being a variable length field) I can gaurantee that the VARCHAR value is unique. Example: Animal(id, animalName, .....) In this case it makes no sense to have the same animalName twice!! Therefore animalName is a suitable PRIMARY KEY, however..... I don't want to limit the length of the animalName, therefore would like to use VARCHAR(255)..... But will this create performance problems?? Cheers for your help, Ben |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > PRIMARY KEY: INT v. VARCHAR(255) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|