>> ok so PRIMARY KEY is just like UNIQUE except that it is the 'primary' key ?
You use these constraints often for candidate keys in your schema, so yes. With the exception that UNIQUE allows for NULL values, while, of course, PRIMARY KEY does not.
Consider the example table User(id, name, email). Suppose id is a key, and so is (name, email) - no user can have the same name AND email. Then you can do this:
Code:
CREATE TABLE (
id INT PRIMARY KEY,
name VARCHAR(30),
email VARCHAR(50),
UNIQUE (name, email)
)
Of course, you can also make (name, email) the primary key and id UNIQUE.
>> KEY == INDEX and speeds up querys (most often, at least with integer fields) by allowing mysql to search for eg every number starting with 1 but does not have to go down all the list?
How indexes work in MySQL -> http://www.mysql.com/doc/en/MySQL_indexes.html
Bookmarks