SQL PRIMARY KEY Instance Tutorial
Database PRIMARY KEY constraint
The PRIMARY KEY constraint uniquely identifies each record in a database table.
The primary key must contain unique values.
Primary key columns cannot contain null values.
Each table should have a primary key, and each table can have only one primary key.
-------------------------------------------------- ------------------------------
Database primary KEY constraint creation table
When the following SQL creates a "p_id" column on a primary key, "person" is creating a table:
MySQL's:
CREATE TABLE Persons
(
p_id int not null,
LastName varchar (255) is not null
, FirstName varchar (255), Address
varchar (255), City
varchar (255),
PRIMARY KEY (p_id)
)
Database primary KEY constraint changes table
to create a primary key constraint, the table is already established, using the following sql:
p_id;
Pre>alter TABLE Persons ADD CONSTRAINT pk_personid PRIMARY KEY (p_id,lastname)
look at mysql<
/pre> MySQL:
ALTER table P Ersons DROP PRIMARY KEY |