Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2003-2008 Curt Hill Index Creation SQL.

Similar presentations


Presentation on theme: "Copyright © 2003-2008 Curt Hill Index Creation SQL."— Presentation transcript:

1 Copyright © 2003-2008 Curt Hill Index Creation SQL

2 Copyright © 2003-2008 Curt Hill Introduction We have already seen that the two basic types of indices are based on B+Trees and Hashing We generally get one index by default on the primary key Now we see how to get a clustered index that is not based primary key

3 Copyright © 2003-2008 Curt Hill SQL There is a Create Index command that allows the construction of an index The index may also be added to a Create Table or an Alter Table This allows the index to allow duplicates or be unique

4 Copyright © 2003-2008 Curt Hill Create Syntax Create [unique] Index name on table (f1[,f2…]) Legend: Reserved, optional, item names Unique may be applied to any candidate key –Not the default Cannot be used on a primary key Other options may be applied by different servers

5 Copyright © 2003-2008 Curt Hill Create Table Syntax An index may be a clause on a Create Table or Alter Table Attached as a clause to a Create Table Index [name] (f1[,f2…]) With an Alter use the Add clause

6 Copyright © 2003-2008 Curt Hill Examples Create unique index on students (name) Create table students ( naid int, name char(20), address char(20), primary key (naid) index (name)) Alter table students add index (name)

7 Specific Oracle, MySQL and SQL Server have additional options These can specify the type of the index –Among other things –These options determine if a hash or Btree We will next look at the MySQL –Oracle and SQL Server are more complicated Copyright © 2003-2008 Curt Hill

8 MySQL syntax Copyright © 2003-2008 Curt Hill Create statement: CREATE [UNIQUE | FULLTEXT | SPATIAL] INDEX index-name [index_type] ON tbl_name (col_name1, … col_name2) [index_type] col_name: col_name [ (length) ] [ ASC | DESC] index_type: [ USING {BTREE | HASH} ]


Download ppt "Copyright © 2003-2008 Curt Hill Index Creation SQL."

Similar presentations


Ads by Google