You are on page 1of 6

CSCI335 Test2 Fall 2020 – 2021

Lebanese International University


School of Arts and Sciences - Department of Computer Science

Course Name : Database Systems Course Code : CSCI335


Date : 10 December Section : All Sections
Instructor : Time : 8:30-9:30 p.m
Auditorium : Seat Number :

Number of pages :7 Allowed Time : 60 minutes


Documents : Not Allowed Calculators : Not Allowed

Problem# Grade Total Grade


Problem1 20
Problem2 40
Problem3 40

/100

Good Luck

Page 1 of 6
CSCI335 Test2 Fall 2020 – 2021

Problem 1: T/F (20 points)

1. We can use DROP statement to remove a database or table permanently from the

system.T 

2. We can insert two records with same roll number in a table if roll is assigned as primary

key.F

3. The result of a SELECT statement can contain duplicate rows. F

4. An attribute declared as UNIQUE can have NULL as its value. F

5. A candidate key can uniquely identify a database record. F

6. An attribute can reference an attribute from another relation with a FOREIGN KEY

constraint. T

7. SQL stands for Semantic Query Language. F

8. During the creation of database schemas, NULL means the field does not have a value;

whereas, NOT NULL means the field must have a value. T

9. The primary key for a record must never be allowed to have a NULL value.T

10. The ON DELETE CASCADE clause of a foreign key constraint would cause related rows in

another table to be set as NULL. F

11.

Page 2 of 6
CSCI335 Test2 Fall 2020 – 2021

Problem 2: MCQ (40 pts) each 4 pts

Consider the following Relational schema and Relations instances.

Book (code: int, title: varchar (50), nbpage: int, price: int)

Author (id: int, name: varchar (10), email: varchar (50))

Write (AuthotID: int, BookCode: int, PublishedDate: date)

Author
Write
id name Email
1 John john@gmail.com AuthorID BookCode PublishedDate
2 Farid farid@hotmail.com 1 5 10/10/2020
3  Harvey Deitel, Paul Deitel hdpd@outlook.com 4 3 2/6/2019
4 Mari mari@liu.edu.lb 4 1 3/11/2021
1 1 1/1/2018

Book
code title Nbpage price
1 Programming with Java 512 50
3 DBMS 250 75
2 Python 300 pages 35
NULL A+ Certificate 550 100

1. Which table should be created first (author / write):


a) Author then write
b) Write then author
c) Could be created in the same time
d) None of the above

2. In the Author table, the violation is:


a) All the id must start with auth-
b) There is a repetition in the id column
c) The name is too long
d) All the ids must contain only numbers
e) There is no violation in Author table
3. Retrieve the information of author number 5, the query is:
a) Select all from author with number=5
b) Select all from author where number=5
f) Select * from author where id=5
c) Cannot write a query because there is no author with id=5 in the table

Page 3 of 6
CSCI335 Test2 Fall 2020 – 2021

4. Retrieve the title of the book with number of page = 512


a) Get title of book condition nbpage = 512
b) Select title of book where nbpage = 512
c) Select title from book condition nbpage = 512
d) Select title from book where nbpage = 512

5. Retrieve the book title written by the author whose ID is 1


a) Select title from book where authorID = 1
b) Select title from book, write where authorID = 1 and authorID = id
c) Select title from book, write where authorID = 1 and bookcode = code
d) Select title from book, write, author where authorID = 1 and authorID = id

6. Change the price of book code 3 to 720


a) Alter table book modify price = 720 where code = 3
b) Update book modify price = 720 where code = 3
c) Update table book set price = 720 where code = 3
d) Alter table book set price = 720 where code = 3

7. Add new book to the book table with code =3, title = database, nbpage = 300 and price =
320
a) Cannot insert, violation
b) Insert into book(3,’database’,300,320)
c) Insert into table book(3,”database”,300,320)
d) Insert into book(“3”,”database”,”300”,”320”)

8. What is the number of tuples retrieved after executing the following query:

Select * from Book

a. 1
b. 2
c. 3
a) 4
9. Which of the following queries will generate an error when executed?
a. Insert into Write values (2 ,2 , 11/12/2020)
b. Insert into Write values (4, 3, 20/2/2020)
c. Insert into Write values (1,5 , 1/5/2019)
a) All of the above
10. Which of the following queries allows us to delete from the Book table all the entries whose
price is above 75:
a. Delete from Book where price is greater than 75
b. Delete from Write where price > 75
c. Delete from Book where price is above 75
a) Delete from Book where price > 75

Page 4 of 6
CSCI335 Test2 Fall 2020 – 2021

Problem 3: SQL Queries(40 pts)


Consider the relational database schema below for keeping tracks of Bikes, Sailors and their
Reservation.

Sailor(sid: INT, sname: varchar(25), rating:INT, age: real)

Bike(bid: INT, bname; varchar(25), color: varchar(10))

Reservation(sid: INT, bid: INT, day: dat

Sailor Reservation
sid sname rating age
sid bid date
22 103 10/10/2019
22 Samer 7 21
31 101 11/12/2020
31 Hani 10 25
22 103 12/10/2021
58 Ramz 10 35 58 105 08/12/2018
i
62 Rita 6 23

Bike
bid bname color

101 Vivi Red

103 Bmx Blue

105 Rockrider Black

A.In which order we must fill the above tables (which table first, second and third). Justify briefly
your answer [4 pts]

Sailor , Bike , Reservation

OR

Bike , sailor , reservation

Page 5 of 6
CSCI335 Test2 Fall 2020 – 2021

B. Write SQL queries that do the following (each 6 pts)


1. Write a query that can be used to create the table Reservation .

Create table reservation ( sid int ,bid int ,date date ,

Primary key (sid , bid ),

Foreign key (sid ) references sailor (sid) ,

Foreign key (bid) references bike(bid)

2. Find the sids and the sname of sailors who have reserved a red bike.

Select sid , sname from sailor s , bike b , reservation r where s.sid = r.sid and

r.bid = b.bid and color = ‘red’

3. Find the name of the sailor(s) who have reserved a red or a blue bike

Select sid , sname from sailor s , bike b , reservation r where s.sid = r.sid and

r.bid = b.bid and color = ‘red’ or color = ‘blue’

4. Add new bike(110,bmx,black) to the bikes table.

Insert into bike values (110, ‘bmx’ , ‘ black’)

5. Remove ‘Bmx from the Bike table

Delete from bike where bname = ‘bmx’

6. Change the rating of Sailor having sid =62 to be 7.

Update sailor set rating = 7 where sid = 62

Page 6 of 6

You might also like