100% found this document useful (2 votes)
2K views9 pages

Section 15

This document provides examples of SQL statements and questions about SQL and relational database concepts. It includes 10 examples of SQL queries with explanations of the answers. It also includes 7 questions about the schema and relationships between tables in the Global Fast Foods sample database.

Uploaded by

scribdpamman
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
100% found this document useful (2 votes)
2K views9 pages

Section 15

This document provides examples of SQL statements and questions about SQL and relational database concepts. It includes 10 examples of SQL queries with explanations of the answers. It also includes 7 questions about the schema and relationships between tables in the Global Fast Foods sample database.

Uploaded by

scribdpamman
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/ 9

Section 15, Practice Guide Anatomy of a SQL Statement, Try

I t/Solve I t Exercises 1-10.



1. Write a SQL statement that demonstrates projection.

select ARTIST_NAME from music;

















2. Write a query that displays the last_name and email addresses for all the people in the DJs on
Demand d_client table. The column headings should appear as Client and Email
Address.

select D_CLIENTS.LAST_NAME as "Client",
D_CLIENTS.EMAIL as "Email Address"
from D_CLIENTS D_CLIENTS




Client Email Address
Peters [email protected]
Jones [email protected]
Vigil [email protected]
3 rows returned in 0.00
seconds



3. The manager of Global Fast Foods decided to give all employees at 5%/hour raise + a $.50
bonus/hour. However, when he looked at the results, he couldn't figure out why the new
raises were not as he predicted. Ms. Doe should have a new salary of $7.59, Mr. Miller's
salary should be $11.00, and Monique Tuttle should be $63.50. He used the following query.
What should he have done?

SELECT last_name, (salary +salary *.05) +.50 FROM f_staffs;

Corrected SQL:

SELECT last_name, (salary +salary *.05) +.50 FROM f_staffs;

LAST_NAME (SALARY+SALARY*.05)+.50
Doe 7.5875
Miller 11
Tuttle 63.5
3 rows returned in 0.01
seconds






4. Which of the following would be the easiest way to see all rows in the d_songs table?
a. SELECT id, title, duration, artist, type_code
b. SELECT columns
c. SELECT *
d. SELECT all

Ans: C


5. If tax = 8.5% * car_cost and license = car_cost * .01%, which value will produce the largest
car payment?
a. Payment = (car_cost * 1.25) + 5.00 - (tax) - (license)
b. Payment = car_cost * 1.25 + 5.00 - (tax - license)

Ans: b)

6. In the example below, identify the keywords, the clause(s), and the statement(s):
SELECT employee_id, last_name FROM employees

Keywords: SELECT, FROM
Clauses: SELECT employee_id
Statement: SELECT employee_id, last_name FROM employees






7. Label each example as SELECTION, PROJECTION, or JOIN.
a. Please give me Mary Adam's email address.
b. I will need each customer's name and the order_total for their order.
c. I would like only the manager_id column, and none of the other columns.

a) SELECTION
b) JOIN
c) PROJECTION

8. Which of the following statements are true?
a. null * 25 = 0;
b. null * 6.00 = 6.00
c. null * .05 = null
d. (null + 1.00) + 5.00 = 5.00

c is true.


9. How will the column headings be labeled in the following example?
SELECT bear_id bears, color AS Color, age age FROM animals;
a. bears, color, age
b. BEARS, COLOR, AGE
c. BEARS, COLOR, age
d. Bears, Color, Age

c is the answer




10. Which of the following words must be in a SELECT statement in order to return all rows?
a. SELECT only
b. SELECT and FROM
c. FROM only
d. SELECT * only


b) is the answer


Section 15, Practice Guide Relational Database Technology,
Try I t/Solve I t Exercises 1-7.

1. The Global Fast Foods database consists of how many tables? __ 9 __ tables

SELECT table_name FROM user_tables;

2. How is the F_SHI FTS table related to the F_STAFFS table?

These two tables are not related

SQL workshop > Object browser > table > F_Shifts

CREATE TABLE "F_SHIFTS"
( "CODE" NUMBER(5,0),
"DESCRIPTION" VARCHAR2(100) CONSTRAINT "F_SFT_DESC_NN" NOT NULL ENABLE,
CONSTRAINT "F_SFT_CODE_PK" PRIMARY KEY ("CODE") ENABLE
)






CREATE TABLE "F_STAFFS"
( "ID" NUMBER(5,0),
"FIRST_NAME" VARCHAR2(25) CONSTRAINT "F_STF_FIRST_NAME_NN" NOT NULL ENABLE,
"LAST_NAME" VARCHAR2(35) CONSTRAINT "F_STF_LAST_NAME_NN" NOT NULL ENABLE,
"BIRTHDATE" DATE CONSTRAINT "F_STF_BIRTHDATE_NN" NOT NULL ENABLE,
"SALARY" NUMBER(8,2) CONSTRAINT "F_STF_SALARY_NN" NOT NULL ENABLE,
"OVERTIME_RATE" NUMBER(5,2),
"TRAINING" VARCHAR2(50),
"STAFF_TYPE" VARCHAR2(20) CONSTRAINT "F_STF_STAFF_TYPE_NN" NOT NULL ENABLE,
"MANAGER_ID" NUMBER(5,0),
"MANAGER_BUDGET" NUMBER(8,2),
"MANAGER_TARGET" NUMBER(8,2),
CONSTRAINT "F_STF_ID_PK" PRIMARY KEY ("ID") ENABLE
)


3. What are the names of the columns in the F_CUSTOMERS table?

select * from F_CUSTOMERS;

ID FIRST_NAME LAST_NAME ADDRESS CITY STATE ZIP PHONE_NUMBER
123 Cole Bee
123 Main
Street
Orlando FL 32838 4075558234
456 Zoe Twee
1009 Oliver
Avenue
Boston MA 12889 7098675309
2 rows returned in
0.01 seconds






4. How many rows of data have been entered in the F_PROMOTI ONAL_MENUS table?


Only two rows are there in this table.

select * from F_PROMOTIONAL_MENUS;

CODE NAME START_DATE END_DATE GIVE_AWAY
100 Back to School 01/Sep/2004 30/Sep/2004 ballpen and highlighter
110 Valentines Special 10/Feb/2004 15/Feb/2004 small box of chocolates
2 rows returned in 0.01
seconds




5.

In the F_FOOD_ITEMS table, column PROMO_CODE is a foreign-key column. What table
and column is this key referencing? "F_PROMOTIONAL_MENUS" ("CODE")

Column Name Data Type Nullable Default Primary Key
FOOD_ITEM_NUMBER NUMBER(5,0) No - 1
DESCRIPTION VARCHAR2(100) No - -
PRICE NUMBER(8,2) No - -
REGULAR_CODE VARCHAR2(3) Yes - -
PROMO_CODE VARCHAR2(3) Yes - -



CREATE TABLE "F_FOOD_ITEMS"
( "FOOD_ITEM_NUMBER" NUMBER(5,0),
"DESCRIPTION" VARCHAR2(100) CONSTRAINT "F_FIM_DESC_NN" NOT NULL ENABLE,
"PRICE" NUMBER(8,2) CONSTRAINT "F_FIM_PRICE_NN" NOT NULL ENABLE,
"REGULAR_CODE" VARCHAR2(3),
"PROMO_CODE" VARCHAR2(3),
CONSTRAINT "F_FIM_FOOD_ITEM_NUMBER_PK" PRIMARY KEY ("FOOD_ITEM_NUMBER") ENABLE
)
/
ALTER TABLE "F_FOOD_ITEMS" ADD CONSTRAINT "F_FIM_PROMO_CODE_FK" FOREIGN KEY ("PROMO_CODE")
REFERENCES "F_PROMOTIONAL_MENUS" ("CODE") ENABLE
/
ALTER TABLE "F_FOOD_ITEMS" ADD CONSTRAINT "F_FIM_REGULAR_CODE_FK" FOREIGN KEY
("REGULAR_CODE")
REFERENCES "F_REGULAR_MENUS" ("CODE") ENABLE
/



Ans: -

In the F_FOOD_ITEMS table, column PROMO_CODE is a foreign-key column. It is
referencing the table and column : "F_PROMOTIONAL_MENUS" ("CODE")

6. List the primary key to foreign key relationships required to go from the F_SHIFTS table to
the F_REGULAR_MENUS table.

CREATE TABLE "F_SHIFTS"
( "CODE" NUMBER(5,0),
"DESCRIPTION" VARCHAR2(100) CONSTRAINT "F_SFT_DESC_NN" NOT NULL ENABLE,
CONSTRAINT "F_SFT_CODE_PK" PRIMARY KEY ("CODE") ENABLE
)
/

CREATE TABLE "F_REGULAR_MENUS"
( "CODE" VARCHAR2(3),
"TYPE" VARCHAR2(30) CONSTRAINT "F_RMU_TYPE_NN" NOT NULL ENABLE,
"HOURS_SERVED" VARCHAR2(30) CONSTRAINT "F_RMU_HOURS_SERVED_NN" NOT NULL ENABLE,
CONSTRAINT "F_RMU_CODE_PK" PRIMARY KEY ("CODE") ENABLE
)


I do not see any relationship between these two tables.


7. Which table(s) contains null values?

The tables F_FOOD_ITEMS and F_STAFFS both contains null values.

You might also like