0% found this document useful (0 votes)
15 views8 pages

DBMS Lab - 4

The document outlines a DBMS lab exercise conducted by Yash Jhaveri, including the creation of three tables: Employee1, Project, and Client, along with their respective attributes. It details the insertion of sample data into the Employee and Project tables and demonstrates various SQL join operations such as Inner Join, Left Join, Right Join, Full Join, Natural Join, Cross Join, and Self Join. Each SQL operation is accompanied by code snippets and screenshots illustrating the results.

Uploaded by

hnpatil2821969
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views8 pages

DBMS Lab - 4

The document outlines a DBMS lab exercise conducted by Yash Jhaveri, including the creation of three tables: Employee1, Project, and Client, along with their respective attributes. It details the insertion of sample data into the Employee and Project tables and demonstrates various SQL join operations such as Inner Join, Left Join, Right Join, Full Join, Natural Join, Cross Join, and Self Join. Each SQL operation is accompanied by code snippets and screenshots illustrating the results.

Uploaded by

hnpatil2821969
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

DBMS Lab – 4

Name: Yash Jhaveri


Student ID: 21124092

→ Table creation query:


CREATE TABLE Employee1 (

EmpID numeric,

EmpFName varchar(20),

EmpLName varchar(20),

Age numeric(65),

EmailId varchar(30),

PhoneNo numeric(10),

Address varchar(50)

);

CREATE TABLE Project (

ProjectID numeric,

EmpID numeric,

ClientID numeric,

ProjectName varchar(30),

ProjectStartDate date

);

CREATE TABLE Client (

ClientID numeric,

ClientName varchar(20),

Age numeric(65),

ClientEmailID varchar(60),

PhoneNo numeric(10),

Address varchar(40),
EmpID numeric

);

→ Inserting Values in the Table:


For Employee Table:
insert into Employee values(1,'Vardhan','Kumar',22,'[email protected]',9876543210,'Delhi');
insert into Employee
values(2,'Himani','Sharma',32,'[email protected]',9977554422,'Mumbai');
insert into Employee
values(3,'Aayushi','Shreshth',25,'[email protected]',9977555121,'Kolkata');
insert into Employee
values(4,'Hemanth','Sharma',25,'[email protected]',9876545666,'Bengaluru');
insert into Employee
values(5,'Swatee','Kapoor',26,'[email protected]',9544567777,'Hyderabad');

Screenshot:

For Project Table:


insert into Project values(111,1,3,'Project1','2019-04-21');
insert into Project values(222,2,1,'Project2','2019-02-12');
insert into Project values(333,3,5,'Project3','2019-01-10');
insert into Project values(444,3,2,'Project4','2019-04-16');
insert into Project values(555,5,4,'Project5','2019-05-23');
insert into Project values(666,9,1,'Project6','2019-01-12');
insert into Project values(777,7,2,'Project7','2019-07-25');
insert into Project values(888,8,3,'Project8','2019-08-20');

Screenshot:

→ Inner Join:
Code:
SELECT Employee1.EmpID, Employee1.EmpFname, Employee1.EmpLname,
Project.ProjectID, Project.ProjectName
FROM Employee1
INNER JOIN Project
ON Employee1.EmpID=Project.EmpID

Screenshot:
→ Left Join:
Code:
SELECT Employee1.EmpID, Employee1.EmpFname, Employee1.EmpLname,
Project.ProjectID, Project.ProjectName
FROM Employee1
LEFT JOIN Project
ON Employee1.EmpID=Project.EmpID;

Screenshot:

→ Right Join:
Code:
SELECT Employee1.EmpID, Employee1.EmpFname, Employee1.EmpLname,
Project.ProjectID, Project.ProjectName
FROM Employee1
right JOIN Project
ON Employee1.EmpID=Project.EmpID
Screenshot:

→ Full Join
Code:
SELECT employee1.EmpID, employee1.EmpFname,
employee1.EmpLname,Project.ProjectID, Project.ProjectName FROM
employee1 LEFT JOIN Project ON employee1.EmpID=Project.EmpID union ALL
SELECT employee1.EmpID, employee1.EmpFname, employee1.EmpLname,
Project.ProjectID, Project.ProjectName FROM employee1 RIGHT JOIN Project
ON employee1.EmpID=Project.EmpID;

Screenshot:
→ Natural Join
Code:
SELECT *FROM Employee
natural JOIN Project;

Screenshot:
→ Cross Join
Code:
SELECT employee1.EmpID, employee1.EmpFname,
employee1.EmpLname FROM employee1 CROSS JOIN Project
Screenshot:
→ Self Join
Code:
SELECT A.PROJECTID,A.EMPID,A.CLIENTID,A.PROJECTNAME FROM PROJECT
A,PROJECT B WHERE A.EMPID-B.CLIENTID<5 AND
A.PROJECTID=B.PROJECTID;

Screenshot:

You might also like