Вы находитесь на странице: 1из 4

Self Test Answers 529

SELF TEST ANSWERS


Create Simple and Complex Views
D, E. Aggregations and joins make a view complex and make DML impossible.
1.
A, B, C. Selection and projection or renaming columns does not make the view complex.

D. Sad but true. Views do not help performance.
2.
A is wrong because a view is only a SELECT statement; it doesnt prerun the query. B is

wrong because the Oracle optimizer will sort out any differences in syntax. C is wrong because,
although views are precompiled, this doesnt affect the speed of compiling a users statement.
3. C. The WITH CHECK OPTION will prevent DML that would cause a row to disappear
from the view.
A, B, D. A is wrong because views are by default created read/write. B is wrong because

the view is a simple view. D is wrong because the statement cannot succeed because the check
option will reject it.

Retrieve Data from Views


A. There is a NOT NULL or PRIMARY KEY constraint on DEPT.DEPTNO.
4.
B, C, D. B is wrong because constraints are enforced on detail tables, not on views. C and

D are wrong because the error message would be different.

Create Private and Public Synonyms


B, D. Public synonyms are not schema objects and so can only be addressed directly. They
5.
can have the same names as schema objects.
A, C. These are wrong because users must be granted privileges on a public synonym before

they can see it or select from it.
6. B. The order of priority is to search the schema namespace before the public namespace, so
it will be the private synonym (to EMPLOYEES) that will be found.
A, C, D. A is wrong because a synonym can exist in both the public namespace and the

schema namespace. C is wrong because the order of priority will find the private synonym first.
D is wrong because it would not be possible to have a table and a private synonym in the same
schema with the same name.
530 Chapter 12: Creating Other Schema Objects

D. The synonym will be fine, but the view will be invalid. Oracle will attempt to recompile
7.
the view, but this will fail.
A, B, C, E. A is wrong because the view will be invalid. B is wrong because the FORCE

keyword can only be applied when creating a view (and it would still be invalid, even so). C is
wrong because the synonym will be fine. E is wrong because views are not dropped implicitly
(unlike indexes and constraints).

Create, Maintain, and Use Sequences


D. The default is NOCYCLE, and the sequence cannot advance further.
8.
A, B, C. A and B are wrong because CYCLE is disabled by default. If it were enabled,

the next number issued would be 1 (not zero) because 1 is the default for START WITH. C is
wrong because under no circumstances will a sequence issue repeating values.
9. A. It is not possible to change the next value of a sequence, so you must re-create it.
B, C, D. B is wrong because, while a NOCYCLE sequence can never reissue numbers,

there is no reason why a new sequence (with the same name) cannot do so. C is wrong because
START WITH can only be specified at creation time. D is wrong because this will not force an
instant cycle; it will only affect what happens when the sequence reaches its MAXVALUE or
MINVALUE.
10. D. If the sequence is being used by other sessions, there is no knowing how many
increments may have taken place between the first and the second INSERT statements.
A, B, C. The answer would be 4, C, except that there could have been increments forced

by other sessions. A and B are wrong because the ROLLBACK will not reverse the sequence
increments.

Create and Maintain Indexes


A, B. Either a UNIQUE or a NONUNIQUE index can be used to enforce a UNIQUE
11.
constraint.
C, D. C is wrong because there is no need to create another index (in fact, you cant index

the same column twice even if you want to). D is wrong because if an index exists, Oracle wont
attempt to create another.
A. The keywords BITMAP and UNIQUE are mutually exclusive. And you wouldnt want
12.
to do this, anyway.
Lab Answer 531

B, C, D. B and C are wrong because a bitmap index can be composite, with columns of

different data types. D is wrong because the bitmap index is not on DEPARTMENT_ID alone,
which would not be possible.
C. It is not possible to change an indexs columns after creation.
13.
A, B, D. B is wrong because the data type is not the problem. A and D are wrong because

an indexs columns are fixed at creation time.

LAB ANSWER
This is a possible solution:
/*create the tables*/
create table sales (sale_id number, channel_id number, product_id number, shop_id number,
day_id number, quantity number);
create table products (product_id number, pname varchar2(20),price number);
create table channels (channel_id number, cname varchar2(20));
create table shops (shop_id number,address varchar2(20));
create table days (day_id number, day date);
/*pre-create indexes to be used for constraints*/
create unique index prod_pk on products(product_id);
create unique index chan_pk on channels(channel_id);
create unique index shop_pk on shops(shop_id);
create unique index day_id on days(day_id);
create unique index sales_pk on sales(sale_id);
/*create bitmap indexes on the dimension columns of the fact table*/
create bitmap index sales_chan on sales(channel_id);
create bitmap index sales_prod on sales(product_id);
create bitmap index sales_shop on sales(shop_id);
create bitmap index sales_date on sales(day_id);
/*add the primary key constraints/*
alter table products add constraint prod_pk primary key (product_id);
alter table channels add constraint chan_pk primary key (channel_id);
alter table shops add constraint shop_pk primary key (shop_id);
alter table days add constraint day_pk primary key (day_id);
alter table sales add constraint sales_pk primary key(sale_id);
/*add the foreign key constraints*/
alter table sales add constraint sales_prod_fk foreign key (product_id) references products;
alter table sales add constraint sales_chan_fk foreign key (channel_id) references channels;
alter table sales add constraint sales_shop_fk foreign key (shop_id) references shops;
alter table sales add constraint sales_day_fk foreign key (day_id) references days;
/*create the sequences for primary keys:
cache many values for the fact table, but don't pre-issue values for the largely static
532 Chapter 12: Creating Other Schema Objects

dimension tables. This will save some memory*/


create sequence sales_seq cache 1000;
create sequence product_seq nocache;
create sequence channel_seq nocache;
create sequence shop_seq nocache;
create sequence day_seq nocache;
/*create a view to analyze sales in several dimensions*/
create view sales_analysis as
select cname,pname,address,day,sum(quantity) total
from sales,channels,products,shops,days
where sales.channel_id=channels.channel_id
and sales.product_id=products.product_id
and sales.shop_id=shops.shop_id
and sales.day_id=days.day_id
group by grouping sets(
(cname,pname,address,day),
(address,pname),
(pname,day));

Вам также может понравиться