中文网站
  Advanced Search
Read the latest Blogs from IT professionals in the field. Read and write community created documents. Need IT help? Ask our staff. Connect with your peers. Check our Tech Shop for posters, books and software tools. Home

11.8 Database Systems: Index Definition in SQL

1. Some SQL implementations includes data de nition commands to create and drop indices. The IBM SAA-SQL commands are

  • An index is created by

create index <index-name>
on r (<attribute-list>)

  • The attribute list is the list of attributes in relation r that form the search key for the index.
  • To create an index on bname for the branch relation:

create index b-index
on branch (bname)

 If the search key is a candidate key, we add the word unique to the de nition:

create unique index b-index
on branch (bname)

  • If bname is not a candidate key, an error message will appear.
  • If the index creation succeeds, any attempt to insert a tuple violating this requirement will fail.
  • The unique keyword is redundant if primary keys have been de ned with integrity constraints already.

2. To remove an index, the command is

drop index <index-name>