0% found this document useful (0 votes)
25 views2 pages

Lab 4

Uploaded by

kahwinson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views2 pages

Lab 4

Uploaded by

kahwinson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

AICT005-4-1-Database Systems SQL

Lab 4

Table: Publisher
PublisherID Name Address
P01 Pearson Bukit Jalil
P02 Deitel Puchong
P03 Rainbow Subang
P04 MacHill Kuala Lumpur

Note: PublisherID is a primary key in Publisher Table

Table: Book
BookID Name Author Price PublishedDate PublisherID
B01 Maths J.Wenton 50.60 10 Jan 2016 P01
B02 Science S.Hanson 100.00 12 Feb 2016 P01
B03 English K.Vince 89.30 9 March 2016 P02
B04 Biology K.Vince 150.80 24 April 2016 P03
B05 Computing J.Denzin NULL NULL NULL

Note: BookID is a primary key in Boo Table


Note: PublisherID is a foreign key in Book Table

1. Using Ms SQL Server, create a new database Lab 4


2. Write query to create the tables given above (you may copy them from lab2)
3. Write query to add each row of data into the tables (you may copy them from lab2)

Attributes Data Type


PublisherID nvarchar(50)
Name nvarchar(50)
Address nvarchar(50)

Attributes Data Type


BookID nvarchar(50)
Name nvarchar(50)
Author nvarchar(50)
Price decimal(10,2)
PublishedDate date
PublisherID nvarchar(50)

Reference:
https://www.w3schools.com/sql/default.asp

Using the SQL ‘Select’ clause:


4. Display a list of publishers showing all details
5. Display a list of books showing only name and author

Diploma Asia Pacific University of Technology & Innovation Page 1 of 2


AICT005-4-1-Database Systems SQL

(Question 6 onwards, begin the SQL statement with Select *……….)


Using the SQL ‘Where’ clause:
6. Display a list of books written by K.Vince
7. Display a list of books published by publisher with ID ‘P01’
8. Display a list of books which cost more than 100
9. Display a list of books which cost less or same as 100

Using ‘Where’ Clause and SQL ‘Between’ operator


10. Display a list of books which cost between 100 and 200
11. Display a list of books which cost not between 100 and 200

Using Where Clause and SQL ‘And’, ‘Or’ operator


12. Display a list of Books where author is ‘S.Hanson’ and Price is 100
13. Display a list of Books where author is ‘J.Wenton’ and Price is 30 (no result displayed, why?)
14. Display a list of Books where author is ‘K.Vince’ or Price is between 50 and 100
15. Display a list of Books where author is ‘K.Vince’ or Price is not between 50 and 100

Using Where Clause and SQL ‘Order By’ Keyword


16. Display a list of all Publishers, show the result in ascending order by publisher name
17. Display a list of Books, display the result in descending order by book name
18. Display a list of Books written by ‘K.Vince’, display the result in descending order by book
name
19. Display a list of Book not written by ‘J.Wenton’ which cost more than 30, display the result in
descending order by price.
20. Display all books except ‘Science’ book, order the result in ascending order by Author and
descending order by price.
21. Display all books except those published by PublisherID ‘P01’, display the result in ascending
order by price.
22. Display a list of Book not written by ‘S.Hanson’, or not cost between 90 and 160, display the
result in ascending order by price.

Diploma Asia Pacific University of Technology & Innovation Page 2 of 2

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy