Professional Documents
Culture Documents
Lab Chapter # 2 KOVID BEHL - N01579154 - ITC-5104-0NA PDF
Lab Chapter # 2 KOVID BEHL - N01579154 - ITC-5104-0NA PDF
Total Marks: 10
Student Id #: N01579154______________________________________________________
Lab exercises You need to be present in the class for your lab to be graded and are to be
submitted within 3 Hours after the class, failing to do the will result in ZERO grade.
DO NOT ZIP THE FILE, JUST SEND AS A WORD OR PDF DOCUMENT THROUGH
BLACKBOARD I WILL NOT ACCEPT SUBMISSION THROUGH EMAIL.
PLEASE MAKE SURE THAT YOU CAPUTURE THE SQL STATEMENT AND THE
RESULT/OUTPUT OF EACH QUESTION AND SUBMIT ALL OF THEM AS ONE
DOCUMENT. FOLLOW THE EXAPLE OF QUESTION # 1.
Review Questions
1. What is a data dictionary?
A data dictionary is a repository of metadata, or information about a database. It is vital
as it holds details such as the database's contents, who has access to it, and the location of
the database. The data dictionary is typically managed by database administrators and is
not typically accessed by general users.
4. What does the use of an asterisk (*) in the SELECT clause of a SELECT statement
represent?
This is used to retrieve every column in the table.
8. What are the guidelines to keep in mind when using a column alias?
We can enclose the column alias in double quotes if:
- It contains blank spaces.
- It contains special symbols.
- To retain case.
Create the JustLee Books database by executing the JLDB_Build.sql script provided with lab
file on the blackboard. Make sure to save the file in your course folder.
In SQL Developer:
1. From the menu, click File, Open and navigate to the JLDB_Build.sql file.
2. Click the file, and then click the Open button. You should see the script. statements in the work
area.
3. From the file menu choose select All
4. Click the Run Script button above the work area to execute the statements. You might be
prompted to select a connection.
Hands-On Assignments:
2. List the title only of all books available in inventory, using the BOOKS table.
SELECT title
FROM books;
3. List the title and publication date for each book in the BOOKS table. Use the column heading
“Publication Date” for the Pubdate field.
SELECT title, pubdate AS "Publication Date"
FROM books;
4. List the customer number for each customer in the CUSTOMERS table, along with the city and
state in which the customer lives.
SELECT customer#, firstname, lastname, city, state
FROM customers;
5. Create a list containing the publisher’s name, the person usually contacted, and the publisher’s
telephone number. Rename the contact column “Contact Person” in the displayed results. (Hint:
Use the PUBLISHER table.)
SELECT name, contact AS "Contact Person", Phone
FROM publisher;
6. Determine which categories are represented in the current book inventory. List each category
only once.
SELECT DISTINCT category
FROM books;
7. List the customer number from the ORDERS table for each customer who has placed an order
with the bookstore. List each customer number only once.
SELECT DISTINCT customer#
FROM orders;
8. Create a list of each book title stored in the BOOKS table and the category in which each book
belongs. Reverse the sequence of the columns so that the category of each book is listed first.
SELECT category, title
FROM books;
9. Create a list of authors that displays the last name followed by the first name for each author. The
last names and first names should be separated by a comma and a blank space.
SELECT lname || ',' || fname
FROM author;
10. List all information for each order item. Include an item total, which can be calculated by
multiplying the Quantity and Paideach columns. Use a column alias for the calculated value to
show the heading “Item Total” in the output.
SELECT orderitems.*, quantity*paideach AS "Item Total"
FROM orderitems;
Advanced Challenge
The management of JustLee Books has submitted two requests. The first is for a mailing list of all
customers stored in the CUSTOMERS table. The second is for a list of the percentage of profit generated
by each book in the BOOKS table. The requests are as follows:
1. Create a mailing list from the CUSTOMERS table. The mailing list should display the name, address,
city, state, and zip code for each customer. Each customer’s name should be listed in order of last
name followed by first name, separated with a comma, and have the column header “Name.” The city
and state should be listed as one column of output, with the values separated by a comma and the
column header “Location.”
SELECT orderitems.*, quantity*paideach AS "Item Total"
FROM orderitems;
2. To determine the percentage of profit for a particular item, subtract the item’s cost from the retail
price to calculate the dollar amount of profit, and then divide the profit by the item’s cost. The
solution is then multiplied by 100 to determine the profit percentage for each book. Use a SELECT
statement to display each book’s title and percentage of profit. For the column displaying the
percentage markup, use “Profit %” as the column heading. Required: Determine the SQL statements
needed to perform the two required tasks. Each statement should be tested to ensure its validity.
Submit documentation of the commands and their results, using the format specified by your
instructor.
SELECT title, ((retail-cost)/cost)*100 AS "Profit%"
FROM books;