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

Bangladesh University of Business and Technology: Database System

The document contains the SQL code to create 5 tables: Depart_ment, employe, Emp_Dep, Building, and Dep_Building. The tables are populated with sample data. Questions/answers are provided at the end to demonstrate querying across the different tables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Bangladesh University of Business and Technology: Database System

The document contains the SQL code to create 5 tables: Depart_ment, employe, Emp_Dep, Building, and Dep_Building. The tables are populated with sample data. Questions/answers are provided at the end to demonstrate querying across the different tables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Bangladesh University of Business and Technology

Fall semester,2021

Course Title: Database system

Course Code: 208

Submitted by: Submitted to:

Name:Afifa Murshida Nazin Md. Anwar Hussen Wadud

ID: 18192103134 Lecturer

Program: B.Sc Engg. in CSE Department of CSE, BUBT

Intake: 41

Section: 04

Group Member:

1. sayeda jannat joti

2. Ashfack Uddin Nabil

3. MD Tayeb

4. Shaminur Rahman

5. Md. Rahid Amin

6. Md.Rakibul Islam

7. Sk. Md. Rumman


Table Creation:

table 1:

SQL:

CREATE TABLE Depart_ment(

Depart_ment_ID int,

Depart_ment_Name varchar(30),

PRIMARY KEY(Depart_ment_ID)

INSERT INTO `depart_ment`(`Depart_ment_ID`, `Depart_ment_Name`)

VALUES

(1, 'CSE'),

(2, 'EEE'),

(3, 'Bangla'),

(4, 'English')
table 2:

SQL:

CREATE TABLE employe(

Employee_ID int,

Employee_name varchar(30),

Employee_Age int,

PRIMARY KEY(Employee_ID)

INSERT INTO `employe`(`Employee_ID`, `Employee_name`, `Employee_Age`) VALUES (1, 'Habib', 35),

(2, 'Habib', 35),

(3, 'rahim', 40),

(4, 'kobir', 75),

(5, 'abdullah', 58),

(6, 'mijan', 60),

(7, 'rofik', 25),

(8, 'robin', 35)


table 3:

SQL:

CREATE TABLE Emp_Dep(

Emp_ID int,

Dep_ID int,

PRIMARY KEY(Emp_ID,Dep_ID),

FOREIGN KEY (Emp_ID) REFERENCES employe(employee_ID),

FOREIGN KEY (Dep_ID) REFERENCES depart_ment(Depart_ment_ID)

INSERT INTO `emp_dep`(`Emp_ID`, `Dep_ID`) VALUES (1, 1),

(3, 2),

(4, 4),

(8, 3),
(7, 1)

table 4:

SQL:

CREATE TABLE Building(

Building_ID int,

Building_Name varchar(30),

PRIMARY KEY(Building_ID)

INSERT INTO `building`(`Building_ID`, `Building_Name`) VALUES (1, 'Building_1'),

(2, 'registrar building'),

(3, 'Building_3'),

(4, 'Building_4')
table 5:

SQL:

CREATE TABLE Dep_Building(

Dep_ID int,

Building_ID int,

PRIMARY KEY(Dep_ID,Building_ID),

FOREIGN KEY (Building_ID) REFERENCES building(Building_ID),

FOREIGN KEY (Dep_ID) REFERENCES depart_ment(depart_ment_ID)

INSERT INTO `dep_building`(`Dep_ID`, `Building_ID`)

VALUES (1, 1),

(2, 3),

(3, 2),

(4, 4)
Answer
Ans 1:

SQL:

SELECT employe.Employee_name FROM employe, building WHERE


employe.Employee_ID=building.Building_ID AND building.Building_Name='registrar_building'

OUTPUT:
2 ans:

SQL:

UPDATE employe SET Employee_Age=60

WHERE depart_ment.Depart_ment_ID=employe.Employee_ID AND Depart_ment_Name='CSE'

OUTPUT:

before

After
ans 3:

SQL:

SELECT MAX(Employee_Age) AS second_largest_age

FROM employe

WHERE Employee_Age < (SELECT MAX(Employee_Age)

FROM employe);

OUTPUT:
Ans to the question No - 7

(a) select name from employee e, books b, loan l where e.empno = l.empno and l.isbn = b.isbn and
b.publisher = ‘McGrawHill’

(b) select name from employee e join loan l on e.empno=l.empno join (select isbn from books where
publisher = 'McGrawHill') x on l.isbn=x.isbn group by e.empno,name having count()= (select count() from
books where publisher=’McGrawHill’)

(c) select name from employee,loan,books where employee.empno=loan.empno and


books.isbn=loan.isbn group by employee.empno, name,books.publisher having count(loan.isbn) >=5

You might also like