Indexes
Indexes allow a DBMS
to access data quicker (please
note: this feature is nonstandard/not
available on all systems). The system
creates this internal data structure
(the index) which causes selection
of rows, when the selection is based
on indexed columns, to occur faster.
This index tells the DBMS where a
certain row is in the table given
an indexed-column value, much like
a book index tells you what page a
given word appears. Let's create an
index for the OwnerID in the AntiqueOwners
column:
CREATE INDEX OID_IDX ON ANTIQUEOWNERS
(OWNERID);
Now on the names:
CREATE INDEX NAME_IDX ON ANTIQUEOWNERS
(OWNERLASTNAME, OWNERFIRSTNAME);
To get rid of an index, drop it:
DROP INDEX OID_IDX;
By the way, you can
also "drop" a table, as well (careful!--that
means that your table is deleted).
In the second example, the index is
kept on the two columns, aggregated
together--strange behavior might occur
in this situation...check the manual
before performing such an operation.
Some DBMS's do not
enforce primary keys; in other words,
the uniqueness of a column is not
enforced automatically. What that
means is, if, for example, I tried
to insert another row into the AntiqueOwners
table with an OwnerID of 02, some
systems will allow me to do that,
even though we do not, as that column
is supposed to be unique to that table
(every row value is supposed to be
different). One way to get around
that is to create a unique index on
the column that we want to be a primary
key, to force the system to enforce
prohibition of duplicates:
CREATE UNIQUE INDEX OID_IDX ON
ANTIQUEOWNERS (OWNERID); |