SQL Basic
SQL HOMESQL Intro
SQL Syntax
SQL Select
SQL Distinct
SQL Where
SQL And & Or
SQL Order By
SQL Insert
SQL Update
SQL Delete
SQL Demo
SQL Try ItSQL Advanced
SQL TopSQL Like
SQL Wildcards
SQL In
SQL Between
SQL Alias
SQL Joins
SQL Inner Join
SQL Left Join
SQL Right Join
SQL Full Join
SQL Union
SQL Select Into
SQL Create DB
SQL Create Table
SQL Constraints
SQL Not Null
SQL Unique
SQL Primary Key
SQL Foreign Key
SQL Check
SQL Default
SQL Create Index
SQL Drop
SQL Alter
SQL Increment
SQL Views
SQL Dates
SQL Nulls
SQL isnull()
SQL Data Types
SQL Functions
SQL FunctionsSQL avg()
SQL count()
SQL first()
SQL last()
SQL max()
SQL min()
SQL sum()
SQL Group By
SQL Having
SQL ucase()
SQL lcase()
SQL mid()
SQL len()
SQL round()
SQL now()
SQL format()
SQL Quick Ref
SQL Hosting
SQL Summary
SQL Quiz
SQL QuizSQL CREATE INDEX Statement
| « Previous | Next Chapter » |
The CREATE INDEX statement is used to create indexes in tables.
Indexes allow the database application to find data fast; without reading the whole table.
Indexes
An index can be created in a table to find data more quickly and efficiently.
The users cannot see the indexes, they are just used to speed up searches/queries.
Note: Updating a table with indexes takes more time than updating a table without (because the indexes also need an update). So you should only create indexes on columns (and tables) that will be frequently searched against.
SQL CREATE INDEX Syntax
Creates an index on a table. Duplicate values are allowed:
| CREATE INDEX index_name ON table_name (column_name) |
SQL CREATE UNIQUE INDEX Syntax
Creates a unique index on a table. Duplicate values are not allowed:
| CREATE UNIQUE INDEX index_name ON table_name (column_name) |
Note: The syntax for creating indexes varies amongst different databases. Therefore: Check the syntax for creating indexes in your database.
CREATE INDEX Example
The SQL statement below creates an index named "PIndex" on the "LastName" column in the "Persons" table:
| CREATE INDEX PIndex ON Persons (LastName) |
If you want to create an index on a combination of columns, you can list the column names within the parentheses, separated by commas:
| CREATE INDEX PIndex ON Persons (LastName, FirstName) |
| « Previous | Next Chapter » |
