MySQL Forums
Forum List  »  Newbie

Re: Primary Key with multiple fields
Posted by: laptop alias
Date: August 27, 2008 10:54AM

That's what the manual's for (http://dev.mysql.com/doc/refman/5.0/en/create-table.html). This is what it has to say:

A PRIMARY KEY is a unique index where all key columns must be defined as NOT NULL. If they are not explicitly declared as NOT NULL, MySQL declares them so implicitly (and silently). A table can have only one PRIMARY KEY. If you do not have a PRIMARY KEY and an application asks for the PRIMARY KEY in your tables, MySQL returns the first UNIQUE index that has no NULL columns as the PRIMARY KEY.
In InnoDB tables, having a long PRIMARY KEY wastes a lot of space. (See Section 13.2.13, “InnoDB Table and Index Structures”.)
In the created table, a PRIMARY KEY is placed first, followed by all UNIQUE indexes, and then the non-unique indexes. This helps the MySQL optimizer to prioritize which index to use and also more quickly to detect duplicated UNIQUE keys.
A PRIMARY KEY can be a multiple-column index. However, you cannot create a multiple-column index using the PRIMARY KEY key attribute in a column specification. Doing so only marks that single column as primary. You must use a separate PRIMARY KEY(index_col_name, ...) clause.

Options: ReplyQuote


Subject
Written By
Posted
Re: Primary Key with multiple fields
August 27, 2008 10:54AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.