0% found this document useful (0 votes)
11 views11 pages

DB2 Ndassignment Theory

Uploaded by

Ashiah Kunar
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)
11 views11 pages

DB2 Ndassignment Theory

Uploaded by

Ashiah Kunar
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/ 11

DB –Assignment(THEORY)2

Name  Ashish Kumar


SecEA
Roll.No. 08
QUE1.
QUE2

A Find the name of suppliers who supply some red


parts.
SELECT DISTINCT Suppliers.sname
FROMSuppliers
JOINCatalogONSuppliers.sid=Catalog.sid JOIN PartsON Catalog.pid
= Parts.pid WHERE Parts.color = 'red';

B Find the sids of suppliers who supply some red or


green parts.
SELECT DISTINCT Suppliers.sid
FROMSuppliers
JOINCatalogONSuppliers.sid=Catalog.sid JOIN Parts ON
Catalog.pid = Parts.pid WHERE Parts.color IN ('red', 'green');
B Find the sids of suppliers who supply some red part
and having cost more than 6000.
SELECTDISTINCTSuppliers.sid FROM Suppliers
JOINCatalogONSuppliers.sid=Catalog.sid JOIN Parts ON
Catalog.pid = Parts.pid
WHEREParts.color='red'ANDCatalog.cost>6000;

QUE3

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

QUE4

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.
QUE5

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.

Candidate Key 4: {Instructor_name, Semester,


Univ_Section#}
Thiscandidatekeyassociatesaclasswithaspecificinstructorin a
particular semester.
Assumesthataninstructorteachesonlyonesectionofacourse in a
given semester.

QUE6

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).

QUE7
QUE8

You might also like