Skip to main content

Index tutorial SQL Server

When we need to improve the performance the first thing comes in your mind is Index, while there are many different things can be done to improve the performance of the system. But indexing of the table should be done carefully which may reduce the query time as unexpected. Although every SQL Server release comes with new updates so we have to know about the index, which one updates comes on Index and which type of index should be used to increase your performance. In this tutorial, we will learn about each type of index available in SQL Server and will explain why/when one could be used to improve the query performance.

In starting I will explain the basic about Index so that new database professional learn about the index in SQL Server.
According to Microsoft Doc, an index is an on-disk structure associated with a table or view that speeds retrieval of rows from the table or view. An index contains keys built from one or more columns in the table or view. These keys are stored in a structure (B-tree) that enables SQL Server to find the row or rows associated with the key values quickly and efficiently.
Type of Index: There are basically two types of index
1-        Clustered Indexes
2-        Non-Clustered Indexes

But some specialized index types are available in SQL Server, these indexes can create on regular tables and datatypes and some work only on specific datatype, please see the following.

1-        ColumnStore Indexes
2-        Full-Text Indexes
3-        XML Indexes
4-        Spatial Indexes
5-        Filtered Indexes

Don’t miss one thing which is more important, sometimes index can create trouble if we do not maintain indexes from time to time.

1-    Index Fragmentation

Popular posts from this blog

Check for changes to an SQL Server table?

Problem: Suppose your team is working on the under-development project so it might be possible continuous work on the database and perform changes in Table, Stored procedure as per requirement, and daily you have to update the testing server database as per changes are done in developing server database then how it is possible to trace those changes. There are a lot of solutions for this problem which is listed below Solution 1: For SQL Server 2000, 2005 and above use the CHECKSUM command SELECTCHECKSUM_AGG(BINARY_CHECKSUM(*))FROMYour_Table_NameWITH (NOLOCK); That will return the same number each time its run as long as the table contents haven't changed. Unfortunately CHECKSUM does not work always properly to detect changes. It is only a primitive checksum and no CRC calculation. Therefore you can't use it to detect all changes, e. g. symmetrical changes result in the same CHECKSUM! Solution 2: 1.Run the following query. Before executing query replace DB_Name with your database name…

Merge and Merge join transformation in SSIS

How to drop multiple tables with common prefix in one query?

Problem: Suppose we have a situation where we need to drop those tables that have some prefixes string, so it is possible to drop those tables with a common prefix in a single query.
Solution: yes it is possible to drop all those tables that have the common prefix in a single query. Using following query you can delete all those tables that begin with a certain prefix string. In where condition just put the common prefix string in where condition (Like ‘prefix%’)
DECLARE@queryNVARCHAR(MAX)=N'';
SELECT@query+=' DROP TABLE ' +QUOTENAME(s.name) +'.'+QUOTENAME(t.name)+';' FROMsys.tablesASt INNERJOINsys.schemasASs ONt.[schema_id]=s.[schema_id] WHEREt.nameLIKE'MX_100%';
EXECsp_executesql@query;
This query may create an issue, if a table has a foreign key relationship, you'll either need to drop them first or arrange the output to drop the tables in a certain order. If you want to monitor exactly what goes on when the query is running then use the following que…