You are on page 1of 7

A Guide to SQL, Ninth Edition Solutions 3-1

Guide to SQL 9th Edition Pratt


Full download at link:

Test Bank: https://testbankpack.com/p/test-bank-for-guide-to-sql-

9th-edition-pratt-111152727x-9781111527273/

Solution Manual: https://testbankpack.com/p/solution-manual-for-

guide-to-sql-9th-edition-pratt-111152727x-9781111527273/

Chapter 3: An Introduction to SQL

Solutions

Answers to Review Questions

1. Use the CREATE TABLE command to create a table by typing the table name and then listing
within a single set of parentheses the columns in the table.
2. Use the DROP TABLE command.
3. CHAR, VARCHAR, DATE, DECIMAL, INT, SMALLINT.
4. Best Data Type:
Oracle SQL Server Access
a. DATE DATETIME DATE
b. CHAR CHAR SHORT TEXT
c. CHAR CHAR SHORT TEXT
d. DECIMAL DECIMAL CURRENCY

5. Valid or Invalid
A Guide to SQL, Ninth Edition Solutions 3-2

a. VALID b. VALID c. INVALID d. INVALID


6. A null data value (or null) is a special value that is used when the actual value for a column is
unknown, unavailable, or not applicable. Use the NOT NULL clause in a CREATE TABLE
command to identify columns that cannot accept null values.
7. Use the INSERT command.
8. Use the SELECT command.
9. Use the UPDATE command.
10. Use the DELETE command.
11. Use the DESCRIBE command in Oracle.
12. [Critical Thinking] Answers will vary. Answers should mention that the difference between
CHAR and VARCHAR is that CHAR is fixed length, while VARCHAR is variable length. This
means that CHAR is always the same size and takes up the same amount of bytes, while
VARCHAR varies. VARCHAR is a good choice when you are storing email addresses and
comments that can vary in size.
13. [Critical Thinking] Answers will vary. Answers should mention that BOOLEAN data type
only stores one of two values; yes or no, on or off, 1 or 0.

Answers to TAL Distributors Exercises

1.
In Oracle, the command is:
CREATE TABLE SALES_REP
(REP_NUM CHAR(2) PRIMARY KEY,
LAST_NAME VARCHAR(15),
FIRST_NAME CHAR(15),
STREET CHAR(15),
CITY CHAR(15),
STATE CHAR(2),
POSTAL_CODE CHAR(5),
COMMISSION NUMBER(7,2),
RATE NUMBER(3,2) );

In Access, the command is:


CREATE TABLE SALES_REP
(REP_NUM CHAR(2) PRIMARY KEY,
LAST_NAME VARCHAR(15),
FIRST_NAME CHAR(15),
STREET CHAR(15),
CITY CHAR(15),
STATE CHAR(2),
POSTAL_CODE CHAR(5),
COMMISSION CURRENCY,
RATE NUMBER);

In SQL Server, the command is:


A Guide to SQL, Ninth Edition Solutions 3-3

CREATE TABLE SALES_REP


(REP_NUM CHAR(2) PRIMARY KEY,
LAST_NAME VARCHAR(15),
FIRST_NAME CHAR(15),
STREET CHAR(15),
CITY CHAR(15),
STATE CHAR(2),
POSTAL_CODE CHAR(5),
COMMISSION NUMERIC(7,2),
RATE NUMERIC(3,2) );

To describe the layout and characteristics of the SALES_REP table, use the DESCRIBE command in Oracle, the
Documenter in Access, and the stored procedure Exec sp_columns in SQL Server.
2.
INSERT INTO SALES_REP
VALUES
('35','Lim','Louise','535 Vincent Dr.','Grove','CA','90092',0,0.05);

To display the contents of the SALES_REP table, use:


SELECT *
FROM SALES_REP;

3.
DROP TABLE SALES_REP;
4. You can obtain the scripts for this text via the Web at login.cengage.com.
5. Use the DESCRIBE command or the Documenter (Access) or exec sp_columns (SQL Server) to view the
layout and characteristics of the REP, CUSTOMER, ORDERS, ITEM, and ORDER_LINE tables.
6. Use the SELECT command to view the data in the REP, CUSTOMER, ORDERS, ITEM, and
ORDER_LINE tables.
7. [Critical Thinking] Answers will vary. The DESCRIPTION field could use the VARCHAR data type because the
descriptions vary in length. Only integers are stored in the ON_HAND and STOREHOUSE fields so these fields
could use the INT data type.

Answers to Colonial Adventure Tours

1.
In Oracle, the command is:
CREATE TABLE ADVENTURE_TRIP
(TRIP_ID DECIMAL(3,0) PRIMARY KEY,
TRIP_NAME VARCHAR(75),
START_LOCATION CHAR(50),
STATE CHAR(2),
DISTANCE NUMBER(4,0),
MAX_GRP_SIZE NUMBER(4,0),
TYPE CHAR(20),
SEASON CHAR(20) );
A Guide to SQL, Ninth Edition Solutions 3-4

In SQL Server, the command is:


CREATE TABLE ADVENTURE_TRIP
(TRIP_ID DECIMAL(3,0) PRIMARY KEY,
TRIP_NAME VARCHAR(75),
START_LOCATION CHAR(50),
STATE CHAR(2),
DISTANCE NUMERIC(4,0),
MAX_GRP_SIZE NUMERIC(4,0),
TYPE CHAR(20),
SEASON CHAR(20) );

In Access, the command is:


CREATE TABLE ADVENTURE_TRIP
(TRIP_ID NUMBER PRIMARY KEY,
TRIP_NAME VARCHAR(75),
START_LOCATION CHAR(50),
STATE CHAR(2),
DISTANCE NUMBER,
MAX_GRP_SIZE NUMBER,
TYPE CHAR(20),
SEASON CHAR(20) );

To describe the layout and characteristics of the ADVENTURE_TRIP table, use the DESCRIBE command in
Oracle, the Documenter in Access, and the stored procedure Exec sp_columns in SQL Server.
2.
INSERT INTO ADVENTURE_TRIP
VALUES
(45,'Jay Peak','Jay','VT',8,8,'Hiking','Summer');

To display the contents of the ADVENTURE_TRIP table, use:


SELECT *
FROM ADVENTURE_TRIP;

3.
DROP TABLE ADVENTURE_TRIP;
4. You can obtain the scripts for this text via the Web at login.cengage.com.
5. Use the DESCRIBE command or the Documenter (Access) or exec sp_columns (SQL Server) to view the
layout and characteristics of the GUIDE, TRIP, RESERVATION, CUSTOMER, and TRIP_GUIDES tables.
6. Use the SELECT command to view the data in the GUIDE, TRIP, RESERVATION, CUSTOMER, and
TRIP_GUIDES tables.

7. [Critical Thinking] Answers will vary. Both the TRIP_NAME and the START_LOCATION
fields could use the VARCHAR data types. The TRIP_ID and MAX_GRP_SIZE fields could
use the INT data type.
CREATE TABLE TRIP
(TRIP_ID INT PRIMARY KEY,
A Guide to SQL, Ninth Edition Solutions 3-5

TRIP_NAME VARCHAR(75),
START_LOCATION VARCHAR(50),
STATE CHAR(2),
DISTANCE DECIMAL(4,0),
MAX_GRP_SIZE INT
TYPE CHAR(20),
SEASON CHAR(20) );

7. [Critical Thinking]
CREATE TABLE TRIP
(TRIP_ID DECIMAL(3,0) PRIMARY KEY,
TRIP_NAME CHAR(75),
START_LOCATION CHAR(75),
STATE CHAR(2),
DISTANCE DECIMAL(4,0),
MAX_GRP_SIZE DECIMAL(4,0),
TYPE CHAR(20),
SEASON CHAR(20) );
A Guide to SQL, Ninth Edition Solutions 3-6

Answers to Solmaris Condominium Group Exercises

1.
In Oracle, the command is:
CREATE TABLE VACATION_UNIT
(CONDO_ID NUMBER(4,0) PRIMARY KEY,
LOCATION_NUM NUMBER(2,0),
UNIT_NUM CHAR(3),
SQR_FT DECIMAL(5,0),
BDRMS DECIMAL(2,0),
BATHS DECIMAL(2,0),
CONDO_FEE NUMBER(6,2),
OWNER_NUM CHAR(5) );

In SQL Server, the command is:


CREATE TABLE VACATION_UNIT
(CONDO_ID NUMERIC(4,0) PRIMARY KEY,
LOCATION_NUM NUMERIC(2,0),
UNIT_NUM CHAR(3),
SQR_FT DECIMAL(5,0),
BDRMS DECIMAL(2,0),
BATHS DECIMAL(2,0),
CONDO_FEE NUMERIC(6,2),
OWNER_NUM CHAR(5) );

In Access, the command is:


CREATE TABLE VACATION_UNIT
(CONDO_ID NUMBER PRIMARY KEY,
LOCATION_NUM NUMBER,
UNIT_NUM CHAR(3),
SQR_FT NUMBER,
BDRMS NUMBER,
BATHS NUMBER,
CONDO_FEE CURRENCY,
OWNER_NUM CHAR(5) );

To describe the layout and characteristics of the VACATION_UNIT table, use the DESCRIBE command in Oracle,
the Documenter in Access, and the stored procedure Exec sp_columns in SQL Server.
2.
INSERT INTO VACATION_UNIT
VALUES
(20,'2','A04',1680,3,3,775.00,'BL720');

To display the contents of the BOAT_SLIP table, use:


SELECT *
FROM VACATION_UNIT;

3.
DROP TABLE VACATION_UNIT;
4. You can obtain the scripts for this text via the Web at login.cengage.com.
5. Use the DESCRIBE command or the Documenter (Access) or exec sp_columns (SQL Server)to view the
layout and characteristics of the LOCATION, OWNER, CONDO_UNIT, SERVICE_CATEGORY and
SERVICE_REQUEST tables.
A Guide to SQL, Ninth Edition Solutions 3-7

6. Use the SELECT command to view the data in the LOCATION, OWNER, CONDO_UNIT,
SERVICE_CATEGORY and SERVICE_REQUEST tables.

7. [Critical Thinking] Answers will vary. Because the length of both the DESCRIPTION and
STATUS fields is 255, you could make an excellent argument that VARCHAR would be a better
choice. With the VARCHAR data type only the actual number of characters will be stored in the
field not 255.

You might also like