Defining Primary key and Foreign key On Tables

vishalneeraj-24503
Posted by vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 714
Primary and Foreign keyword is used to create Primary key and Foreign key on columns.
Create Parent Table
CREATE TABLE Department 
(
Dept_ID int PRIMARY KEY, --Define primary key
Name varchar (50) NOT NULL,
Address varchar(100) NULL
)
Go

Create Child Table
CREATE TABLE Employee_Master 
(
Employee_Id int PRIMARY KEY, --Define primary key
Employee_Name varchar (50) NOT NULL,
Pan_No varchar(10) NULL,
--Define foreign key
Dept_ID int FOREIGN KEY REFERENCES Department(Dept_ID)
)

Comments or Responses

Login to post response