primary key

From PmaWiki
Jump to: navigation, search

A primary key is an index over one or more fields in a table with unique values for each single row in this table.

Every table should have a primary key for easier accessing/identifying data in this table.

There can only be one primary key per table and it is named always PRIMARY.

In fact a primary key is just an unique key with the name PRIMARY.

If no primary key is defined MySQL will use first unique key as primary key if there is one.

You can create the primary key when creating the table (in phpMyAdmin just check the primary key radio buttons for each field you wish to be part of the primary key).

You can also add a primary key to an existing table with ALTER TABLE or CREATE INDEX (in phpMyAdmin you can just click on 'add index' on the table structure page below the listed fields).

[edit] See also

Personal tools