Primary Key
The Primary Key Constraint Uniquely identifies each Record in a Table. Primary key Must Contain Unique Values and it won't accept NULL values.
PRIMARY KEY = UNIQUE + NOT NULL
Each table should have a primary key, and each table can have only one Primary Key..
Syntax For Creating Primary Key..
Method (1) :-
CREATE TABLE SAMPLE
(
id int identity(1,1) Primary Key,
First_Name varchar(10) not null,
Last_Name varchar(10) not null
)
Method (2) :-
CREATE TABLE SAMPLE
(
id int identity(1,1),
First_Name varchar(10) not null,
Last_Name varchar(10) not null
primary key (id)
)
Method (3):-
CREATE TABLE SAMPLE
(
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)
)
(
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)
)
No comments:
Post a Comment