Anda di halaman 1dari 3

Self Test Answers 483

SELF TEST ANSWERS


Categorize the Main Database Objects
D. The schema will default to the current user.
1.
A, B, C, E. A is wrong because all tables must be in a schema. B is wrong because the

creation will succeed. C is wrong because the SYS schema is not a default schema. E is wrong
because while there is a notional user PUBLIC, he does not have a schema at all.
A. Indexes have their own namespace.
2.
B, C, D, E. Stored procedures, synonyms, tables, and views exist in the same namespace.

D, E. D violates the rule that a table name must begin with a letter, and E violates the rule
3.
that a table name cannot be a reserved word. Both rules can be bypassed by using double quotes.
A, B, C. These are wrong because all will succeed (though A and B are not exactly sensible).

Review the Table Structure


A, C. A heap is a table of variable length rows in random order.
4.
B, D, E. B is wrong because a heap table can only be one table. D and E are wrong because

a heap table can (and usually will) have indexes and a primary key.

List the Data Types that Are Available for Columns


A, C, D, E, F. All these are variable length data types.
5.
B. CHAR columns are fixed length.

D. The number will be rounded to 1 digit, and the string will cast as a date.
6.
A, B, C. Automatic rounding and type casting will correct the errors, though ideally they

would not occur.
D. STRING is not an internal data type.
7.
A, B, C. CHAR, FLOAT, and INTEGER are all internal data types, though not as widely

used as some others.

Create a Simple Table


C. The condition applies only to the rows selected for insert, not to the table creation.
8.
A, B, D. A is wrong because the statement is syntactically correct. B is wrong because the

condition does not apply to the DDL, only to the DML. D is wrong because the condition will
exclude all rows from selection.
484 Chapter 11: Using DDL Statements to Create and Manage Tables

D. Check and not null constraints are not dependent on any structures other than the table
9.
to which they apply and so can safely be copied to a new table.
A, B,C, E. A is wrong because not null and check constraint will be applied to the new

table. B, C, and E are wrong because these constraints need other objects (indexes or a parent
table) and so are not copied.

Explain How Constraints Are Created at the Time of Table Creation


C, D. Unique and primary key constraints are enforced with indexes.
10.
A, B. Check and not null constraints do not rely on indexes.

C. A constraint violation will force a roll back of the current statement but nothing else.
11.
A, B, D, E. A is wrong because all statements that have succeeded remain intact. B and D

are wrong because there is no commit of anything until it is specifically requested. E is wrong
because the whole statement will be rolled back, not just the failed row.

LAB ANSWER
A possible solution:

The SUBSCRIBERS table:


create table subscribers
(id number(4,0) constraint sub_id_pk primary key,
name varchar2(20) constraint sub_name_nn not null);

The TELEPHONES table:


create table telephones
(telno number (7,0) constraint tel_telno_pk primary key
constraint tel_telno_ck check (telno between 1000000 and 9999999),
activated date default sysdate,
active varchar2(1) constraint tel_active_nn not null
constraint tel_active_ck check(active='Y' or active='N'),
subscriber number(4,0) constraint tel_sub_fk references subscribers,
constraint tel_active_yn check((active='Y' and subscriber is not null)
or (active='N' and subscriber is null))
);
Lab Answer 485

This table has a constraint on the ACTIVE column that will permit only Y or N, depending
on whether there is a value in the SUBSCRIBER column. This constraint is too complex to
define in line with the column, because it references other columns. SUBSCRIBER, if not
null, must match a row in SUBSCRIBERS.
The CALLS table:
create table calls
(telno number (7,0) constraint calls_telno_fk references telephones,
starttime date constraint calls_start_nn not null,
endtime date constraint calls_end_nn not null,
constraint calls_pk primary key(telno,starttime),
constraint calls_endtime_ck check(endtime > starttime));

Two constraints are defined at the table level, not the column level. The primary key cannot be
defined in line with a column because it is based on two columns: one telephone can make many
calls, but not two that begin at the same time (at least, not with current technology). The final
constraint compares the start and end times of the call and so cannot be defined in line.

Anda mungkin juga menyukai