Friday, 14 November 2014

Clustred Index



A clustered index sorts and stores the data rows of the table or view in order based on the clustered index key. The clustered index is implemented as a B-tree index structure that supports fast retrieval of the rows, based on their clustered index key values.

Example:
      CREATE TABLE SAMPLE10
      (
            ID INT ,
            NAME VARCHAR(10),
            TYPE_DESC VARCHAR(50)
      )

Syntax:
CREATE <Index type> INDEX <Index name> ON <Table name> (Column1,Column2,...)

Creating index on single column:


CREATE CLUSTERED INDEX IDX_SAMPLE10_CLU ON SAMPLE10 (ID)

Result:




Drop Index:
DROP INDEX SAMPLE10.IDX_SAMPLE10_CLU

Result:

Creating index on multiple column:
CREATE CLUSTERED INDEX IDX_SAMPLE10_CLU ON SAMPLE10 (ID,NAME)

            Result:


Drop Index:
DROP INDEX SAMPLE10.IDX_SAMPLE10_CLU

Result:

No comments:

Post a Comment