DB2 Ndassignment Theory
DB2 Ndassignment Theory
QUE3
i
ii
Teams:
team_id (Primary Key) team_name(varchar2[10]) City
(varchar2[50])
coach_id (Foreign Key referencing Coach)
captain_id(ForeignKeyreferencingPlayer)
Players:
player_id (Primary Key) player_name(varchar2[10]) Position
(varchar2[10]) skill_level (varchar2[10])
team_id(ForeignKeyreferencingTeams)
InjuryRecords:
record_id(PrimaryKey)
player_id (Foreign Key referencing Players) Otherinjury-
relatedattributes(varchar2[50])
Games:
game_id(PrimaryKey) Date (date)
host_team_id (Foreign Key referencing Teams)
guest_team_id(ForeignKeyreferencingTeams) host_score (int)
guest_score(int)
iii
QUE4
STUDT:
Ssn(PrimaryKey) COURSE:
Course#(PrimaryKey) ENROLL:
Ssn (Foreign Key referencing STUDENT)
Course#(ForeignKeyreferencingCOURSE)
BOOK_ADOPTION:
Course#(ForeignKeyreferencingCOURSE) Book_isbn (Foreign Key
referencing TEXT)
TEXT:
Book_isbn(PrimaryKey)
Assumptions:
1. EachstudenthasauniqueSocialSecurityNumber(Ssn).
2. Eachcoursehasauniquecoursenumber(Course#).
3. TheENROLLrelationassociatesstudentswithcourses.
4. TheBOOK_ADOPTIONrelationlinkscoursestoadopted
textbooks.
5. TheTEXTrelationcontainsinformationabouttextbooks,with
each textbook having a unique ISBN.
QUE5
CandidateKey1:{Course#,Univ_Section#}
1. Thiscandidatekeyassumesthateachcoursesection
(Univ_Section#) is unique across all courses.
2. Ituniquelyidentifiesaclassbasedonthecombinationofthe
course number (Course#) and the section number
(Univ_Section#).
3. Notwoclassescanhavethesamecoursenumberandsection
number.
CandidateKey2:{Course#,Semester,Univ_Sectio
n#}
Thiscandidatekeyconsidersthesemesterasanadditional attribute.
It uniquely identifies a class within a specific semester.
Assumesthatnotwoclasseswiththesamecoursenumber, section
number, and semester exist.
CandidateKey3:{Course#,Building_code,Room#}
Thiscandidatekeyidentifiesaclassbasedonthecourse number,
building code, and room number.
Assumesthateachroominabuildingisuniqueforagiven course.
QUE6
A. RelationalDatabaseSchemaforE-CommerceTransaction
System
Customers:
CREATE TABLE Products ( product_id INT PRIMARY KEY,
product_nameVARCHAR(255), price DECIMAL(10, 2),
categoryVARCHAR(50),
);
Products:
CREATE TABLE Products ( product_id INT PRIMARY KEY,
product_nameVARCHAR(255), price DECIMAL(10, 2),
categoryVARCHAR(50),
);
Orders:
CREATETABLEOrders(
order_idINTPRIMARYKEY, customer_id INT, order_date DATE,
FOREIGNKEY(customer_id)REFERENCES Customers(customer_id)
);
Order_Items:
CREATE TABLE Order_Items ( order_item_idINTPRIMARYKEY,
order_id INT,
product_idINT, quantity INT,
FOREIGN KEY (order_id) REFERENCES Orders(order_id),
FOREIGNKEY(product_id)REFERENCESProducts(product_id)
);
B. SQLthatareneededbyyourdatabaseapplication.
1.
SELECTproduct_name,price FROM Products
WHEREcategory='Electronics';
Getthetotalrevenueforaspecificcustomer:
2.
SELECTSUM(p.price*oi.quantity)AStotal_revenue FROM Orders o
JOIN Order_Items oi ON o.order_id = oi.order_id
JOINProductspONoi.product_id=p.product_id WHERE
o.customer_id = 123;
3.
SELECTp.product_name,SUM(oi.quantity)AStotal_sold FROM
Products p
JOINOrder_ItemsoiONp.product_id=oi.product_id GROUP BY
p.product_name
ORDERBYtotal_soldDESC LIMIT 10;
C. Basedontheexpecteduseofthedatabase,consider
indexing the following attributes:
1. customer_idintheCustomerstable(forefficientcustomer lookups).
2. product_idintheProductstable(forquickproductretrieval).
3. order_idintheOrderstable(fororder-relatedqueries). 4.order_date
in the Orders table (if frequent date-based queries are expected).
QUE7
QUE8