A Guide to SQL, Ninth Edition Solutions 3-1
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
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
6. A null data value (or null) is a special value that is used when the actual value for a column is
7. Use the INSERT command.
9. Use the UPDATE command.
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
13. [Critical Thinking] Answers will vary. Answers should mention that BOOLEAN data type
A Guide to SQL, Ninth Edition Solutions 3-2
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),
In Access, the command is:
CREATE TABLE SALES_REP
(REP_NUM CHAR(2) PRIMARY KEY,
LAST_NAME VARCHAR(15),
FIRST_NAME CHAR(15),
In SQL Server, the command is:
CREATE TABLE SALES_REP
(REP_NUM CHAR(2) PRIMARY KEY,
LAST_NAME VARCHAR(15),
FIRST_NAME CHAR(15),
STREET CHAR(15),
To describe the layout and characteristics of the SALES_REP table, use the DESCRIBE command in Oracle, the
2.
INSERT INTO SALES_REP
To display the contents of the SALES_REP table, use:
3.
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
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),
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),
In Access, the command is:
CREATE TABLE ADVENTURE_TRIP
(TRIP_ID NUMBER PRIMARY KEY,
TRIP_NAME VARCHAR(75),
START_LOCATION CHAR(50),
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.
A Guide to SQL, Ninth Edition Solutions 3-4
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.
7. [Critical Thinking]
CREATE TABLE TRIP
(TRIP_ID DECIMAL(3,0) PRIMARY KEY,
A Guide to SQL, Ninth Edition Solutions 3-5
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),
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),
In Access, the command is:
CREATE TABLE VACATION_UNIT
(CONDO_ID NUMBER PRIMARY KEY,
LOCATION_NUM NUMBER,
UNIT_NUM CHAR(3),
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.
To display the contents of the BOAT_SLIP table, use:
SELECT *
FROM VACATION_UNIT;
3.
5. Use the DESCRIBE command or the Documenter (Access) or exec sp_columns (SQL Server)to view the
7. [Critical Thinking] Answers will vary. Because the length of both the DESCRIPTION and