+91 90691 39140 | +1 253 214 3115 | info@hub4tech.com | hub4tech

SQL Server Indexes Interview Questions and Answers

1
What is an index?

Indexes of SQL Server are similar to the indexes in books. They help SQL Server retrieve the data quicker. Indexes are of two types. Clustered indexes and non-clustered indexes. Rows in the table are stored in the order of the clustered index key.
There can be only one clustered index per table.
Non-clustered indexes have their own storage separate from the table data storage.
Non-clustered indexes are stored as B-tree structures.
Leaf level nodes having the index key and it's row locater

2
Explain Having clause and Where clause?

Having Clause: This clause is used for specifying a search condition for a group or an aggregate. It can only be used with a SELECT statement. It’s often used with GROUP BY clause without which its synonymous to a WHERE clause.

E.g.: SELECT Id, Name, Age FROM Customers
GROUP BY Age
HAVING Age>10
ORDER BYAge;

Where Clause: This clause is used to narrow down the dataset being dealt with following a condition.

SELECT Id, Name, Age FROM Customers
WHERE Age>10

It is strongly recommended to use a Where clause with every Select Statement to avoid a table scan and reduce the number of rows to be returned. It can be used with Select, Update, Delete etc statements.

3
Disadvantages of the Indexes.

Use of intexes slow down Data modification operations (such as INSERT, UPDATE, DELETE).
Every time data changes in the table, all the indexes need to be updated.
Indexes need disk space, the more indexes you have, more disk space is used.

4
Do you know what is fill factor and pad index?

A fill factor is a specification done during the creation of indexes so that a particular amount of space can be left on a leaf level page to decrease the occurrence of page splits when the data has to be accommodated in the future.

A pad index specifies index padding. When it is set to ON, then the free space percentage per the fill factor specification is applied to the intermediate-level pages of the index. When it is set to OFF, the fill factor is not specified and enough space is left for a maximum size row that an index can have

5
Define Clustered and Non-Clustered Index.

Clustered index exists as sorted row on disk.
Clustered index re-orders the table record.
Clustered index contains record in the leaf level of the B-tree.
There can be only one Clustered index possible in a table.

Non-clustered is the index in which logical order doesn’t match with physical order of stored data on disk.
Non-clustered index contains index key to the table records in the leaf level.
There can be one or more Non-clustered indexes in a table.

Copyright ©2015 Hub4Tech.com, All Rights Reserved. Hub4Tech™ is registered trademark of Hub4tech Portal Services Pvt. Ltd.
All trademarks and logos appearing on this website are the property of their respective owners.
FOLLOW US