Docsity

COMP 100 SQL Chapter 03, Exercises of Information and Communications Technology (ICT)

Toggle sidebar
bg1
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
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. 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.
pf3
pf4
pf5

Partial preview of the text

Download COMP 100 SQL Chapter 03 and more Exercises Information and Communications Technology (ICT) in PDF only on Docsity!

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. 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

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: 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.

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;

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;

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,

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) );

Answers to Solmaris Condominium Group Exercises

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.

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;

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.