MAdrid - John PAulFinal - 02 - INFOMgt - NationalBookStore - Case Scenario

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Madrid John Paul B.

February 14, 2020


BSIT 2 - 1

Final Term Graded Exercise No. 2


Perform the instructions indicated below using MS SQL Server’s Query Analyzer. Write
on a one whole sheet of yellow paper the SQL commands used in executing the instructions or
the answers to the questions indicated.

Note: Use the National Bookstore database for this exercise. -*

Important: Use the shortest possible SQL statements!

1. For every book, list its book code, book title, publisher code, and publisher name. The list
should be alphabetically listed by book title.
ANS: select Book.BOOK_CODE,Book.BOOK_TITLE,Book.PUB_CODE,Publisher.PUB_CODE from
Book, Publisher where Book.PUB_CODE=publisher.PUB_CODE order by (BOOK_TITLE)

2. What is the first record in the list?

ANS:
Madrid John Paul B. February 14, 2020
BSIT 2 - 1

3. List the book title and book code for every book published by Bantam Books that has a book
price greater than $10 arranged by book code.
ANS: select BOOK_TITLE, BOOK_CODE from Book where PUB_CODE ='BB'and BOOK_PRICE >10
order by (BOOK_CODE)

4. How many records are displayed in (3)?


ANS: 3

5. List the book title of every CS book type published by Best and Furrow.
ANS: select BOOK_TITLE from Book where BOOK_TYPE ='CS'and PUB_CODE ='BF'

6. How many records are displayed in (5)?


ANS: 4

7. List the names of the author together with his/her corresponding publisher. The names
should be in the format Last Name, First Name e.g. Rizal, Jose
ANS: select concat(AUTHOR_LAST,', ', AUTHOR_FIRST)as AUTHOR_NAME,Publisher.PUB_NAME
from Author, Publisher, Written, Book where
Publisher.PUB_CODE=Book.PUB_CODEandBook.BOOK_CODE=Written.BOOK_CODEandWritten.AUTH
OR_NO=Author.AUTHOR_NO
Madrid John Paul B. February 14, 2020
BSIT 2 - 1

8. What is the last record in the list?


ANS: Wray, Robert

9. Generate the following report:


Book Title Quantity On Hand Unit Price

ANS: select Book.BOOK_TITLE,Inventory.UNITS_ON_HAND,Book.BOOK_CODE from Book,


Inventory where Book.BOOK_CODE=Inventory.BOOK_CODE
Madrid John Paul B. February 14, 2020
BSIT 2 - 1

10. How many records are displayed?


ANS: 34
11. For every book authored by an author whose last name starts with either A, C, or O,
permanently add the words New Edition at the end of the title. (Ex. Database Systems New
Edition)
ANS: update Book
set BOOK_TITLE =concat(BOOK_TITLE,' New Edition')from Written, Author
where
Book.BOOK_CODE=Written.BOOK_CODEandWritten.AUTHOR_NO=Author.AUTHOR_NOandAuthor.AUT
HOR_LASTlike'[ACO]%'

select BOOK_TITLE from Book, Written, Author


where
Book.BOOK_CODE=Written.BOOK_CODEandWritten.AUTHOR_NO=Author.AUTHOR_NOandAuthor.AUT
HOR_LASTlike'[ACO]%'
Madrid John Paul B. February 14, 2020
BSIT 2 - 1

12. How many records were affected by (11)?


ANS: 13

13. Permanently add the word Publishing to the Publisher’s name if the publisher is from New
York but only if the name does not have it yet. (Example: Random HousePublishing)
ANS: update Publisher set PUB_NAME =concat(PUB_NAME,' Publishing')
where PUB_CITY ='New York'and PUB_NAME notlike'%Publishing'

select PUB_NAME from Publisher


where PUB_CITY ='New York'and PUB_NAME like'%Publishing'

14. What would be the publisher’s name of the third record when you display all publishers from
New York after doing (13)?
ANS: Pocket Books Publishing

15. Permanently add the word The in the book title for those books whose title starts with S, P,
H, Y, N, or X but only for those books whose publisher is from New York. (Ex. The Castle)
ANS: update Book set BOOK_TITLE =concat('The ', BOOK_TITLE)from Publisher
where BOOK_TITLE
like'[SPHYNX]%'andBook.PUB_CODE=Publisher.PUB_CODEandPublisher.PUB_CITY='New York'

select BOOK_TITLE from Book, Publisher


where BOOK_TITLE
like'The%'andBook.PUB_CODE=Publisher.PUB_CODEandPublisher.PUB_CITY='New York'
Madrid John Paul B. February 14, 2020
BSIT 2 - 1

16. How many records were affected in (15)?


ANS: 8

17. Generate the following report taking note of the sample output:
Book Title Publisher – Location
Cujo The Signet Publishing - New York, NY

ANS: select BOOK_TITLE as 'Book Title',concat(PUB_NAME,' - ', PUB_CITY,', ',


PUB_STATE)as'Publisher - Location'from Book, Publisher
whereBook.PUB_CODE=Publisher.PUB_CODE
Madrid John Paul B. February 14, 2020
BSIT 2 - 1

18. What is the last record in the list?


ANS:

19. Generate the following report taking note of the sample output:
Book Title Publisher Branch Number Units on Hand
Cujo The Signet Publishing 1 1

ANS: selectBook.BOOK_TITLEas'Book
Title',Publisher.PUB_NAMEas'Publisher',Inventory.BRANCH_NOas'Branch
Number',Inventory.UNITS_ON_HANDas'Units on Hand'from Book, Publisher, Inventory
where BOOK.PUB_CODE =Publisher.PUB_CODEand BOOK.BOOK_CODE =Inventory.BOOK_CODE
Madrid John Paul B. February 14, 2020
BSIT 2 - 1

0200 1 1
0200 2 3

20. What is the last record displayed in (19)?

ANS:

Make sure you wrote the SQL statements for 1, 3, 5, 7, 9, 11, 13, 15, 17, and 19 and
answers to 2, 4, 6, 8, 10, 12, 14, 16, 18 and 20.

Log off from MS SQL Server, log off from Windows, arrange the chairs, submit your
paper to the proctor, and quietly leave the room.

You might also like