How many primary keys are possible in a table开发者_开发技巧 in MySQL database.
You can't have several of what is called "primary". The answer is: one. A primary key can contain several columns, though. Then it's what you called a "composite primary key"
For this kind of question, you will always find an answer in the manual:
http://dev.mysql.com/doc/refman/5.5/en/create-table.html
You can only have one primary key and it can be composed (or not). Also you can have many unique indexes which are logicaly identical to primary keys (but some functions are not aviable for them)
you should understand primary key as "the" first index of a table, on many RDBMS it is mandatory to have a primary key in order to have other indexes
You can only have one primary key. From the MySQL documentation:
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.
You posted a comment about composite primary keys. I suggest doing some reading from the MySQL manual to learn about them http://dev.mysql.com/doc/refman/5.5/en/create-table.html. Plus there are question here on SO about composite primary keys you just have to look for them.
One, hence "primary". You can have other "unique" keys/indexes on a table that signify uniqueness in that column/columns (and would likely be referred to as a candidate key).
One.
You can however use several fields to construct the primary key, if that is what you are looking for.
精彩评论