Primary KEY constraints of the rimary key database
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)
)
SQL Server/Oracle/MS Access:
Create table Persons
(
P_Id int not null primary key,
LastName varchar (255) not null,
FirstName varchar (255 ),
Address varchar (255 ),
City varchar (255)
)
Use the following SQL Syntax: CREATE TABLE Persons
(
P_Id int not null,
LastName varchar (255) not null,
FirstName varchar (255 ),
Address varchar (255 ),
City varchar (255 ),
CONSTRAINT pk_PersonID primary key (P_Id, LastName)
)
When you want to create a "P_Id" column for the primary key constraint of a database to change the table, the table has been created. Use the following SQL:
SQL Server/Oracle/MS Access:
Alter table Persons
Add primary key (P_Id)
To make the primary key constraint of the name and determine a primary key constraint for multiple columns, use the following SQL Syntax:
SQL Server/Oracle/MS Access:
Alter table Persons
Add constraint pk_PersonID primary key (P_Id, LastName)
Note: If you use the alter table statement to add a primary key, the primary key column (Sunday) must have been declared as not containing a null value (the first time the TABLE was created ). One of the key constraints for dropping is to discard a primary key constraint and use the following SQL: MySQL: ALTER TABLE Persons
DROP PRIMARY KEY
SQL Server/Oracle/MS Access:
Alter table Persons
Drop constraint pk_PersonID