PDA

View Full Version : MySQL Differences...


Bhuwan
02-13-2006, 03:18 PM
difference beween

UNIQUE KEY
PRIMARY KEY
and a regular
KEY

Xenon
02-13-2006, 03:55 PM
there can only be ONE primary key, it's usually the id key.
normally the datablocks are stored in order to this key (if you have an autoindex for example)

unique key means, that every value is there only once, no two rows can have the same unique key (for example username of the usertable)

each primary key is a unique key, but not every unique key is a primary of course

Paul M
02-13-2006, 04:01 PM
and a regular key is an index key that does not have to be unique.

Xenon
02-13-2006, 04:14 PM
unfortunatelly the name is badchosen, as an index is not really a key.

regarding databasetheory, a key has to identify a single row. and a normal key in mysql doesn't identify.

so if you hear a someone talking about a key in the theoretical aspect, he always means a unique key ;)

Bhuwan
02-13-2006, 05:36 PM
Thanks everyone!
So the difference between a PRIMARY KEY and a UNIQUE KEY is that a UNIQUE key can be NULL and a PRIMARY KEY cannot be NULL?

Xenon
02-13-2006, 10:16 PM
short said: yes ^^