In this article, I am going to use the following tables for the examples:-
CREATE TABLE [dbo]. [Employee](
[Empid] [Int] IDENTITY (1, 1) NOT NULL Primary key,
[EmpNumber] [nvarchar](50) NOT NULL,
[EmpFirstName] [nvarchar](150) NOT NULL,
[EmpLAStName] [nvarchar](150) NULL,
[EmpEmail] [nvarchar](150) NULL,
[Managerid] [int] NULL
)
CREATE TABLE [dbo].[Department](
[Departmentid] [int] IDENTITY (1, 1) NOT NULL primary key,
[DepartmentName] [nvarchar](255) NOT NULL
)
CREATE TABLE [dbo].[EmpdepartmentInfo]
(
Empdepartmentid int identity(1,1) primary key,
Empid int not null,
departmentid int not null
)
SQL scripts for entering the data into the table Employee:-
Insert Into Employee (EmpNumber,EmpFirstName,EmpLAStName,EmpEmail,Managerid)
Values('A001','Samir','Singh','samir@abc.com',2)
Insert Into Employee (EmpNumber,EmpFirstName,EmpLAStName,EmpEmail,Managerid)
Values('A002','Amit','Kumar','amit@abc.com',1)
Insert Into Employee (EmpNumber,EmpFirstName,EmpLAStName,EmpEmail,Managerid)
Values('A003','Neha','Sharma','neha@abc.com',1)
Insert Into Employee (EmpNumber,EmpFirstName,EmpLAStName,EmpEmail,Managerid)
Values('A004','Vivek','Kumar','vivek@abc.com',1)
Insert Into Employee (EmpNumber,EmpFirstName,EmpLAStName,EmpEmail,Managerid)
Values('A005',' AvinASh', 'Dubey','avinASh@abc.com',2)
Insert Into Employee (EmpNumber,EmpFirstName,EmpLAStName,EmpEmail,Managerid)
Values('A006',' Sanjay','Kumar',' sanjay@abc.com',5)
Insert Into Employee (EmpNumber,EmpFirstName,EmpLAStName,EmpEmail,Managerid)
Values('A007','Rajiv','Kumar','rajiv@abc.com',5)
Insert Into Employee (EmpNumber,EmpFirstName,EmpLAStName,EmpEmail,Managerid)
Values('A008','Manish','Kumar','manish@abc.com',6)
SQL scripts for entering the data into the table Department:-
Insert Into Department(DepartmentName)
Values('Testing')
Insert Into Department(DepartmentName)
Values('Admin')
Insert Into Department(DepartmentName)
Values('HR')
Insert Into Department(DepartmentName)
Values('Technology')
SQL scripts for entering the data into the table EmpdepartmentInfo:-
Insert Into [EmpdepartmentInfo](empid, departmentid)
Values(1,1)
Insert Into [EmpdepartmentInfo](empid, departmentid)
Values(2,2)
Insert Into [EmpdepartmentInfo](empid, departmentid)
Values(3,3)
Insert Into [EmpdepartmentInfo](empid, departmentid)
Values(4,4)
Insert Into [EmpdepartmentInfo](empid, departmentid)
Values(4,5)
Insert Into [EmpdepartmentInfo](empid, departmentid)
Values(5,1)
Insert Into [EmpdepartmentInfo](empid, departmentid)
Values(6,2)
Insert Into [EmpdepartmentInfo](empid, departmentid)
Values(7,3)
Insert Into [EmpdepartmentInfo](empid, departmentid)
Values(8,4)