0% found this document useful (0 votes)
6 views

SQL Practical 5

The document outlines the creation and management of tables for a company database, including tables for employees, managers, branches, and projects. It provides SQL commands for creating, inserting, and querying data from these tables. Additionally, it includes various SQL queries to fetch employee details, their associated branches, managers, and projects based on specific conditions.

Uploaded by

FYCS34 HARSH
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

SQL Practical 5

The document outlines the creation and management of tables for a company database, including tables for employees, managers, branches, and projects. It provides SQL commands for creating, inserting, and querying data from these tables. Additionally, it includes various SQL queries to fetch employee details, their associated branches, managers, and projects based on specific conditions.

Uploaded by

FYCS34 HARSH
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Practical No-5

Create the following tables


1)Company
Branch Name of the employee Employee id salary Manager under
no. work

01 Suresh E1 25000 M1

02 Ramesh E2 22000 M1

03 Dinesh E3 21000 M2

04 Kalpesh E4 20000 M1

05 Alpesh E5 21600 M3

06 Adesh E6 26000 M5

07 Rajesh E7 27000 M3

08 Zareen E8 30000 M4

09 Seema E9 20000 M2

10 Esha E10 27500 M2


2)Manager
Manager Manager Branch no
Id Name

M1 Dipak 01

M2 Saniya 02

M3 Amar 01

M4 Robin 03

M5 Sunita 04
3)Branch
Branch No Branch

01 Andheri

02 Sion

03 Dadar

04 Churchgate
05 Thane
4) Project
Project Project of the department Staff appointed for the project

P1 Admin E1

P2 ICT M1

P3 Sales E5

P4 Admin M4

P5 Accounts E6

P6 HR E4

Create a table Manager.


create table Manager (Manager_id varchar(20), manager_name varchar(20),branch_no
smallint);

Describe table Manager.


describe manager;

Insert the values in table Manager.


insert into Manager values('M1', 'Dipak', 01),('M2', 'Saniya',02),('M3', 'Amar', 03),('M4', 'Robin',
04),('M5', 'Sunita', 05);

Display all the values of table Manager.


select *from Manager;

Create a table Branch.


create table branch(branch_no smallint , branch_name varchar(20));

Insert the values in table Branch.


insert into branch values('01', 'Andheri'),('02', 'Sion'),('03', 'Dadar'),('04', 'Churchgate'),('05',
'Thane');

Display all the values of table Branch.


select*from branch;

Create a Project .
create table project(project_id varchar(20) , project_name varchar(20),staff varchar(20));

Insert the values in table Project.


insert into
PROJECTvalues('P1','admin','E1'),('P2','ICT','M1'),('P3','Sales','E5'),('P2','admin','M4'),('P1','acco
unts','E6'),('P1','HR','E4');

Display all of the table projects.


select*from project;

Fetch the details of the employee and branch which they belong to
SELECT e.emply_name,b.branch_no from Company e inner join branch b on
e.branch_no=b.branch_no;

Select one more column of Salary from Company in above query


SELECT e.emply_name,b.branch_no, e.salary from Company e inner join branch b on
e.branch_no=b.branch_no;

Fetch the details of all the employees and their branch .


SELECT e.emply_name,b.branch_no from Company e left join branch b on
e.branch_no=b.branch_no;

Fetch the details of the employee and all branch which they belong to
SELECT e.emply_name,b.branch_no from Company e right join branch b on
e.branch_no=b.branch_no;

Fetch the details of the employee whose salary is 20000


SELECT e.emply_name,b.branch_no, e.salary from Company e inner join branch b on
e.branch_no=b.branch_no where salary=20000;

Fetch the details of the employee whose salary is 27000


SELECT e.emply_name,b.branch_no, e.salary from Company e inner join branch b on
e.branch_no=b.branch_no where salary=27000;

Fetch the details of all the employees, their manager, their department and the project
they work on.
SELECT e.emply_name,b.branch_no, m.manager_name, p. project_name from Company e left
join branch b on e.branch_no=b.branch_no
join manager m on m.manager_id=e.manager_id left join project p on p.staff=e.emp_id;

You might also like