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

Relational Model- Practice Problem2

The document outlines a practice problem for a Database Systems course, focusing on a Retailer Store database schema that tracks customer orders. It includes details about the tables CUSTOMER, ORDER, PRODUCT, and ORDER_DETAIL, along with SQL commands for various operations. The task requires determining the success or failure of specific SQL operations and providing explanations for each outcome.

Uploaded by

tfaizanvr
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)
2 views

Relational Model- Practice Problem2

The document outlines a practice problem for a Database Systems course, focusing on a Retailer Store database schema that tracks customer orders. It includes details about the tables CUSTOMER, ORDER, PRODUCT, and ORDER_DETAIL, along with SQL commands for various operations. The task requires determining the success or failure of specific SQL operations and providing explanations for each outcome.

Uploaded by

tfaizanvr
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/ 2

National University of Computer and Emerging Sciences, Lahore Campus

Course: Database Systems


Program: BS(Computer Science)
Instructor: Muhammad Ishaq Raza

Practice Problem: Relational Model (2)

Consider the following State and Schema of a Retailer Store database. It keeps track of the orders placed by the
customers.
CUSTOMER
cid cname city ORDER
100 Ismail Karachi oid odate cid
200 Isbah Lahore 1 2018-01-20 200
300 Tahreem Islamabad 3 2018-01-20 600
600 Izaan Lahore 5 2018-02-15 300
700 Khadija Karachi 7 2018-02-20 800
800 Alia Lahore

PRODUCT ORDER_DETAIL
Pid pname price company oid pid quantity discountPercent
10 Nutella 250 Ferrero 1 10 2 15
20 Kinder Joy 60 Ferrero 1 70 6 25
40 Milo 30 Nestle 3 10 1 15
50 Maggi Noodle 25 Nestle 5 10 3 15
70 Donuts 50 Dunkin Brands 5 40 4 15
80 Horlicks 400 GSK 5 50 5 25
7 10 2 15

CREATE TABLE customer ( CREATE TABLE product (


cid INT NOT NULL, pid INT NOT NULL,
cname VARCHAR(30), pname VARCHAR(30) UNIQUE,
city VARCHAR(30), price DECIMAL(9,2),
PRIMARY KEY (cid) company VARCHAR(30),
); PRIMARY KEY (pid)
);

CREATE TABLE order ( CREATE TABLE order_detail (


oid INT NOT NULL, oid INT NOT NULL,
odate DATE, pid INT NOT NULL,
cid INT, quantity INT,
PRIMARY KEY (oid), discountPercent INT,
FOREIGN KEY (cid) REFERENCES customer(cid) ON PRIMARY KEY (oid, pid),
DELETE SET NULL ON UPDATE CASCADE CHECK (quantity>0),
); FOREIGN KEY (oid) REFERENCES order(oid) ON
DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (pid) REFERENCES product(pid) ON
DELETE CASCADE ON UPDATE CASCADE
);
Q. Apply following operations on the above database. State if the operation would be carried out successfully or not.
Explain your answer briefly. In case of successful operation indicate the changes that will be made to the above database
and in case of Reject state the error that occurred. Please note that all operations are independent.

a) INSERT INTO ORDER_DETAIL (oid, pid, quantity, discountPercent) VALUES (1, 70, NULL, NULL);
Accept  Explain:
Reject 

b) UPDATE ORDER_DETAIL SET discountPercent = ‘20’;


Accept  Explain:
Reject 

c) UPDATE ORDER SET oid = 4 WHERE oid=5;


Accept  Explain:
Reject 

d) DELETE FROM customer WHERE cname = ‘Izaan’;


Accept  Explain:
Reject 

e) DELETE FROM order;


Accept  Explain:
Reject 

You might also like