Professional Documents
Culture Documents
Assignment# 3: Name: Mah Noor (f2021105007) Sehar Maqsood (f2021105137) Section: Y3
Assignment# 3: Name: Mah Noor (f2021105007) Sehar Maqsood (f2021105137) Section: Y3
Assignment# 3: Name: Mah Noor (f2021105007) Sehar Maqsood (f2021105137) Section: Y3
1|Page
Question # 1: Convert the ER/EER to Relational schema (in SQL) using
the conversion steps/rules discussed in the theory Week10 lecture
slides. You may choose any entities of
your choice.
a) Strong Entity set with Simple attributes (05 points)
2|Page
go
use db_2
go
book_name varchar(25),
book_author varchar(15),
book_price money,
3|Page
b) Strong Entity Set with Composite Attributes (05 points)
4|Page
create table tbl_student
student_fname varchar(15),
student_lname varchar(15),
student_age int,
student_department varchar(15),
values(1,'Jazib', 'Bajwa',23,'Marketing')
5|Pa ge
insert into tbl_student(student_id, student_fname,
student_lname,student_age,student_department)
6|Pa ge
create table tbl_bookshop
book_name varchar(25),
book_author varchar(15),
book_price money,
7|Page
insert into tbl_bookshop(book_id, book_author, book_name, book_price)
book_language varchar(15),
book_id int,
values('B1', 'English', 1)
values('B1','Urdu', 1)
values('B2', 'English',2)
values('B2', 'Urdu', 2)
values('B3', 'English', 3)
values('B3', 'Turkish', 3)
values('B4', 'English', 4)
8|Pa ge
select *from tbl_bookshop1
d) Unary Relationship
9|Pa ge
create table tbl_student1
student_name varchar(15),
student_age int,
student_semester varchar(15),
roomate_name varchar(15),
insert into
tbl_student1(student_id,student_name,student_age,student_semester,roomate_n
ame)
insert into
tbl_student1(student_id,student_name,student_age,student_semester,roomate_n
ame)
10 | P a g e
insert into
tbl_student1(student_id,student_name,student_age,student_semester,roomate_n
ame)
insert into
tbl_student1(student_id,student_name,student_age,student_semester,roomate_n
ame)
11 | P a g e
create table tbl_teacher
teacher_name varchar(15),
teacher_phone int,
teacher_course varchar(15),
coworker_name varchar(15)
12 | P a g e
insert into tbl_teacher(teacher_id, teacher_name, teacher_phone, teacher_course,
coworker_name)
13 | P a g e
create table tbl_course
course_name varchar(15),
course_units int
values(2, 'Database', 3)
prerequisite_name varchar(15),
14 | P a g e
constraint pk_1foreign_key foreign key (course_id)
values('SE' , 1)
values('DSA' , 2)
values('Spanish I' , 3)
15 | P a g e
e) Binary Relationships
• Binary Relationship with Cardinality Ratio m: n (10 points)
16 | P a g e
create table tbl_order
order_amount money
values(1, 1500)
values(2, 2000)
values(3, 2500)
values(4,3000)
17 | P a g e
create table tbl_make
values(1,101)
values(2, 102)
values(3, 103)
values(4, 104)
product_number int
values(101, 100)
values(102, 200)
values(103, 150)
18 | P a g e
insert into tbl_product(product_id, product_number)
values(104, 180)
19 | P a g e
create table tbl_course
course_name varchar(15),
course_units int
values(2, 'Database', 3)
semester_id varchar(10) ,
20 | P a g e
course_idd int
references tbl_course(course_id)
values(101, '4th', 1)
values(102, '2nd', 2)
values(103, '7th', 3)
21 | P a g e
• Binary Relationship with Cardinality Ratio m:1 (10 points)
22 | P a g e
create table tbl_player
player_name varchar(15),
t_id int
values(3, 'Ahmad',101)
23 | P a g e
insert into tbl_player(player_id, player_name, t_id)
values(4,'Mubashir', 103)
team_name varchar(10)
values(101, 'Thunder')
values(102, 'Gladiators')
values(103, 'Strikers')
24 | P a g e
• Binary Relationship with Cardinality Ratio 1:1
o Both sides have partial participation. (10 points)
25 | P a g e
create table tbl_manager
manager_name varchar(10),
d_id int
values(101, 'Ahmad' , 1)
values(102, 'Zayan' , 2)
values(103, 'Altamash', 3)
26 | P a g e
create table tbl_department
department_name varchar(15)
values (3,'Cybersecurity')
27 | P a g e
o One side has partial participation. (10 points)
28 | P a g e
create table tbl_manager
manager_name varchar(10),
values(101, 'Ahmad' )
values(102, 'Zayan' )
values(103, 'Altamash')
29 | P a g e
department_name varchar(15),
m_id int
30 | P a g e
o Both sides have total participation. (10 points)
31 | P a g e
create table tbl_manages
manager_name varchar(10),
department_name varchar(15)
insert into
tbl_manages(manager_id,manager_name,department_id,department_name)
insert into
tbl_manages(manager_id,manager_name,department_id,department_name)
insert into
tbl_manages(manager_id,manager_name,department_id,department_name)
32 | P a g e
f) Binary Relationship with Weak Entity Set (10 points)
33 | P a g e
create table tbl_customer
customer_name varchar(15),
customer_address varchar(15),
customer_phone int
34 | P a g e
create table tbl_loan
loan_date date ,
c_id int
values(101, '2002/02/12', 1)
values(202, '1999/12/04', 2)
values(304, '2000/08/18', 3)
35 | P a g e
g) Ternary Relationship (10 points)
36 | P a g e
create table tbl_chemist
chemist_name varchar(15),
chemist_phone int,
37 | P a g e
serial_no varchar(10) not null unique,
equipment_cost money
values('GH-13456', 2000)
values('XY-6795', 1000)
values('AB-4557', 1500)
project_date date
values(101, '2000/12/01')
values(401, '2005/08/19')
values(901, '2023/02/22')
38 | P a g e
create table tbl_assigned
s_no varchar(15),
assigned_date date
39 | P a g e
h) Mapping EER Diagrams to Relational Schema
• Create a separate relation for each superclass and subclass. (10
points)
40 | P a g e
create table tbl_person
person_name varchar(10),
person_age int
41 | P a g e
values(3, 'Zayan', 18)
student_gpa varchar(10),
p_id int
values('3,19' , 1)
values('3,89',2)
values('4.0' ,3)
employee_salary money,
ps_id int
values(50000, 1)
42 | P a g e
insert into tbl_employee(employee_salary, ps_id)
values(60000, 2)
values(80000, 3)
43 | P a g e
• Create relations for subclass only. (10 points)
create table tbl_studentt
person_age int ,
student_gpa varchar(10),
person_age int ,
employee_salary money,
44 | P a g e
)
45 | P a g e
• Create a single relation with one type attribute. (10 points)
create table tbl_personn
person_age int ,
employee_salary money,
46 | P a g e
student_gpa varchar(10),
person_type varchar(10)
47 | P a g e
• Create a single relation with multiple type attributes. (10 points)
48 | P a g e
create table tbl_personn
person_age int ,
employee_salary money,
student_gpa varchar(10),
person_type varchar(10)
insert into
tbl_personn(person_id,person_name,person_age,employee_salary,student_gpa,
person_type)
49 | P a g e
insert into
tbl_personn(person_id,person_name,person_age,employee_salary,student_gpa,
person_type)
insert into
tbl_personn(person_id,person_name,person_age,employee_salary,student_gpa,
person_type)
insert into
tbl_personn(person_id,person_name,person_age,employee_salary,student_gpa,
person_type)
insert into
tbl_personn(person_id,person_name,person_age,employee_salary,student_gpa,
person_type)
50 | P a g e
51 | P a g e
52 | P a g e