Practicals of INDEX and SEQUENCE
PRACTICAL – 6
1. What is
Index ?
Ans :- An
Index is a copy of selected columns of data from a table that can be searched
very efficiently that also includes a low-level disk block address or direct
link to the complete row of data it was copied from. Some databases extend the
power of indexing by letting developers create indexes on functions or
expressions.
2. Create a
Simple Index idx_order on order amount from the orders table.
Ans:-create
index idx_order on ordered(atm);
3. Create a
unique index idx_order1 number and customer number columns of the orders table.
Ans:- create unique index idx_order1 on
ordered(atm,cnum);
4. What is
sequence?
Ans :- A
Sequence is a set of integers 1,2,3… that are generated in order on demand.
Sequences are frequently used in databases because many applications require
each row in a table to contain a unique value and sequences provide an easy way
to generate them.
5. Create a
sequence order_seq with the following parameters, Incremented by 3, cache 4 and
which will generate the numbers from 1 to 9999 in ascending order.
Ans:- create sequence order_seq1 start with
3 increment by 3 Minvalue 1 Maxvalue
9999 cache 4;
6. Select
the current value of the order_seq.
Ans:-select order_seq1.Currval from dual;
7. Select
the next value of the order_seq.
Ans:-select order_seq1.nextval from dual;
8. Create table order1(onum varchar2(5), odate date), insert
the values for onum,odate in the table order1. The order_seq must be used to
generate onum and odate must be set to system date.
Ans:-insert into order1(onum,odate) values(order_seq1.nextval,sysdate);
9. Consider the same query as above but you have to insert
onum like [MMYY(seq_no)] ex: if current date is 22-SEP-06 & the value
generated by sequence is 1 then your order number must be 22091.
Ans:-insert into order1(onum,odate) values(To_char(sysdate,’mm-yy’)||order_seq1.nextval,sysdate)
10. Change the interval 3 to1 of the sequence order_seq.
Comments
Post a Comment