SQL Step-by-Step (18) Index

Source: Internet
Author: User

Index

Indexes allow the DBMS to access data more quickly. The system creates this internal data structure (that is, the index), which causes the query to search for rows when the query is indexed, so that queries are much faster. This index notifies the DBMS to find a row in the table for a given column index value, which is somewhat like the index of the book that tells you which page you can find for a given word. Now let's create an index for ownerid in the antiqueowners column:

CREATE INDEX oid_idx on Antiqueowners (ownerid);

The following statement is created for the name, so:

CREATE INDEX name_idx on Antiqueowners (Ownerlastname, ownerfirstname);

To delete an index, you can use the drop:

DROP INDEX Oid_idx;

As in the previous tutorial, we can also "drop" (delete) a table. In the second example above, the index is created on two columns.

Some DBMS do not force a primary key, in other words, the uniqueness of the class is not enforced automatically. What does it mean, as if it sounds foggy. Well, for example, if you're inserting another line into the Antiqueowners table, such as this ownerid is 02, some systems can let you do this even if we require that all rows have different values. To avoid two rows having the same value, we have a way to overcome it by creating a unique index on the column, where we need it to be the primary key so that the system does not replicate:

CREATE UNIQUE INDEX oid_idx on Antiqueowners (ownerid);



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.