Indexes: 
Index is used for faster access of data from table and will show records in the table in ascending 
order or descending order. Index in SQLSERVER will works automaticall.there is no need to open or 
to close and index. 
Types of indexes: 
1. Clustered index 
2. non-clustered index 
Clustered index: 
1. A table can contain only one clustered index. If table contains primary key column then on that 
column clustered index will work. 
2. This index will change the physical order of records in the table based on indexed column. 
Non-clustered index: 
1. A table can contain 249 non-clustered indexes. 
2. If table contains uni-constraints then on that column non clustered index will work.it will not 
change the physical order of records in the table but with the help of reference (book index & index 
key) of the table. 
3. it will show the records in ascending or descending order. 
SYNTAX: 
CREATE[UNIQUE][CLUSTERED/NON-CLUSTERED] 
INDEX<INDEX_NAME> 
ON<TABLE_NAME>(<COLUMN_NAME>[DESC]) 
TO DELETE INDEX: 
DROP INDEX<TABLE_NAME><INDEX_NAME> 
CLUSTERED INDEX: 
CREATE CLUSTEREDINDEX MYINDEX1 
ON EMPLOYEE(ENO) 
SELECT * FROM EMPLOYEE 
(ENO WILL BE IN ASCENDING ORDER)
DROP INDEX EMPLOYEE.MYINDEX1 
SELECT * FROM EMPLOYEE 
(ENO WILL BE IN ASCENDING ORDER) 
NON-CLUSTERED INDEX: 
CREATE NONCLUSTEREDINDEX MYINDEX2 
ON EMPLIST (ENO) 
INCLUDE(ENAME,SAL) 
SELECT * FROM EMPLIST 
(ENO WILL BE IN ASCENDING ORDER) 
DROP INDEX EMPLIST.MYINDEX2 
SELECTR * FROM EMPLIST 
(ENO WILL BE IN PREVIOUS ORDER) 
MULTIPLE NONCLUSTERED INDEX: 
CREATE NONCLUSTEREDINDEX MYINDEX3 
ON EMPLOYEE(ENO) 
INCLUDE(ENAME,SAL) 
CREATE NONCLUSTEREDINDEX MYINDEX4 
ON EMPLOYEE(SAL) 
INCLUDE(ENAME,SAL) 
SELECT * FROM EMPLOYEE WHERE ENO>100 
SELECT * FROM EMPLOYEE WHERE SAL>1000 
NOTE: 
If The Table Contains Multiple Nonclustered Indexes Then Two Conditions Should Be Satisfied 
1. Select Statement With Where Clause 
2. Indexed Column In Where Clause

Indexes

  • 1.
    Indexes: Index isused for faster access of data from table and will show records in the table in ascending order or descending order. Index in SQLSERVER will works automaticall.there is no need to open or to close and index. Types of indexes: 1. Clustered index 2. non-clustered index Clustered index: 1. A table can contain only one clustered index. If table contains primary key column then on that column clustered index will work. 2. This index will change the physical order of records in the table based on indexed column. Non-clustered index: 1. A table can contain 249 non-clustered indexes. 2. If table contains uni-constraints then on that column non clustered index will work.it will not change the physical order of records in the table but with the help of reference (book index & index key) of the table. 3. it will show the records in ascending or descending order. SYNTAX: CREATE[UNIQUE][CLUSTERED/NON-CLUSTERED] INDEX<INDEX_NAME> ON<TABLE_NAME>(<COLUMN_NAME>[DESC]) TO DELETE INDEX: DROP INDEX<TABLE_NAME><INDEX_NAME> CLUSTERED INDEX: CREATE CLUSTEREDINDEX MYINDEX1 ON EMPLOYEE(ENO) SELECT * FROM EMPLOYEE (ENO WILL BE IN ASCENDING ORDER)
  • 2.
    DROP INDEX EMPLOYEE.MYINDEX1 SELECT * FROM EMPLOYEE (ENO WILL BE IN ASCENDING ORDER) NON-CLUSTERED INDEX: CREATE NONCLUSTEREDINDEX MYINDEX2 ON EMPLIST (ENO) INCLUDE(ENAME,SAL) SELECT * FROM EMPLIST (ENO WILL BE IN ASCENDING ORDER) DROP INDEX EMPLIST.MYINDEX2 SELECTR * FROM EMPLIST (ENO WILL BE IN PREVIOUS ORDER) MULTIPLE NONCLUSTERED INDEX: CREATE NONCLUSTEREDINDEX MYINDEX3 ON EMPLOYEE(ENO) INCLUDE(ENAME,SAL) CREATE NONCLUSTEREDINDEX MYINDEX4 ON EMPLOYEE(SAL) INCLUDE(ENAME,SAL) SELECT * FROM EMPLOYEE WHERE ENO>100 SELECT * FROM EMPLOYEE WHERE SAL>1000 NOTE: If The Table Contains Multiple Nonclustered Indexes Then Two Conditions Should Be Satisfied 1. Select Statement With Where Clause 2. Indexed Column In Where Clause