The PRIMARY KEY means unique and it identifies each record in a table uniquely. It must contain UNIQUE values and the value should not be NULL values. A table can have only one PRIMARY KEY .
PRIMARY KEY Diagram
PRIMARY KEY EXAMPLE:
CREATE TABLE [dbo].[customer](
[CustomerID] int NOT NULL PRIMARY KEY,
[CustomerName] [varchar](50) NULL,
[CustomerLocation] [varchar](50) NULL,
[State] [varchar](50) NULL,
[City] [varchar](50) NULL,
[phoneno] [int] NULL,
[pincode] [int] NULL,
[Email] [varchar](100) NULL
)
Create primary key on existing Table
Requirement: To create primary key on ID field of Students Table.
ALTER TABLE STUDENTS ADD PRIMARY KEY (ID)
HOW TO CREATE PRIMARY KEY ON MULTIPLE COLUMNS?
ALTER TABLE STUDENTS ADD CONSTRAINT PK_STUDENTS PRIMARY KEY(ID,STUDENTNAME)