SQL PRIMARY KEY instance tutorial
Database primary key constraints
The primary key constraint uniquely identifies each record in a database table.
The primary key must contain unique values.
The primary key column cannot contain null values.
Each table should have a primary key, and each table can have only one primary key.
--------------------------------------------------------------------------------
Create Table with database primary key constraints
When the following SQL statement creates the "P_Id" column on a primary key, "person" creates a table:
MySQL:
Create table Persons(P_Id int not null,LastName varchar (255) not null,FirstName varchar (255), Address varchar (255), City varchar (255), primary key (P_Id ))
Change table with database primary key constraints
To create a column named "P_Id" for the primary key constraint, the table has been created. Use the following SQL statement:
Alter table PersonsADD CONSTRAINT pk_PersonID primary key (P_Id, LastName)
Look at mysql
MySQL:
Alter table PersonsDROP PRIMARY KEY |