What happens when declaring an additional index on the primary key in Oracle SQL? -
i have multi-part question:
my journey began when trying figure out if can have descending/ascending primary keys in oracle sql.
there doesn't seem syntax along lines of create table mytab (id int primary key desc);
or create table mytab (id int, constraint pk primary key(id desc));
later learned oracle implicitly creates index primary key enforce constraints. figured create index it, , make index descending.
create index myind on mytab (id desc);
this worked, when did query see indices existed got this:
> select index_name user_indexes table_name = 'mytab'; index_name ------------------------------ sys_c0011939 myind
i see implicitly created index there own index... tried see if rid of implicitly created index creating index primary key during table create:
create table mytab (id int primary key using index (create index myind on mytab (id asc)));
this worked:
> select index_name user_indexes table_name = 'mytab'; index_name ------------------------------ myind
interestingly, using desc index direction gives me following error:
specified index cannot used enforce constraint.
so questions are:
- does mean descending primary keys not possible in oracle sql?
- if so, why desc disallow primary key constraints being enforced?
- what behavior/effect of creating index separately in first example? desc worked there... happens when primary key has 2 indices on it? function same way db allows desc part of primary key specification?
oracle creates indexes double-linked lists, every index can traversed in ascending or descending order when needed.
for multi-column indexes, however, can add desc
keyword have 1 or more columns stored in descending order respect other columns.
this has limited usefulness , not used - can useful when creating index support particular order by
clause in particular query (but not all) columns sorted in descending order.
Comments
Post a Comment