Primary Key & Unique ID in PhpMyAdmin

by on July 9th, 2007

A primary key is used to uniquely identify each row in a table. It can either be part of the actual record itself, or it can be an artificial field (one that has nothing to do with the actual record). A primary key can consist of one or more fields on a table. When multiple fields are used as a primary key, they are called a composite key.

Primary keys can be specified either when the table is created (using CREATE TABLE) or by changing the existing table structure (using ALTER TABLE).

CREATE TABLE Customer (SID integer, Last_Name varchar(30), First_Name varchar(30), PRIMARY KEY (SID));

Suppose You have list of students and the table (browse table mode) contains their names in a column and their enrollment numbers in the other column. If you have to select a particular student then there should be another column (browse table mode) against each student containing its ID. You will go to table and create another row with the name, lets say ID and assign it as a primary key. Now you can auto-generate numbers for the rows which will be added more in this table and select any student by its ID.