Skip to main content

Difference between Clustered index and Non clustered index

  • When you create a new table there will not be any index on it. A table without any clustered index is called a Heap Table. Heap table contains data in unsorted way, that means the data rows are not stored in any particular order. The data pages are not linked in a linked list. 
  • Clustered Index: A clustered index is a special type of index that reorders the way records in the table are physically stored. There for table can have only one clustered index. The leaf nodes of a clustered index contain the actual data. 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. The pages in each level of the index, including the data pages in the leaf level, are linked in a doubly-linked list. 
  • Non Clustered Index:  A non-clustered index is a special type of index in which the logical order of the index doesn't match with physical order of the rows on disk. The leaf node of a clustered index does not consist of data pages. The leaf nodes contain index rows.



• In which scenarios you would use a Heap Table?
Heap table are used as staging tables, during import/export/ETL processes. Typically get truncated before the process starts. Data population happen faster, if large amount of data is there data retrieval will be very slow.






Comments

Popular posts from this blog

  Microsoft Power BI- Solve Problem  "Map and Filled Map Visuals aren't Enabled"   When you try to use Map or Filled Map from Visuals for the 1st time , you may get the following warning : "Map and Filled Map Visuals are disabled". This means you need to go to Options and have to enable these Visuals. Go to File ->Options and Settings-> Options -> Security-> Enable Map and Filled Map Visuals. (After this, in some cases you may need to close and reopen Power BI desktop) Now Go to Add Visual Then double click on Map or Filled Map. After that, you will be able to add Location, Legends etc. without any issues.

Difference between Clustered Index Scan and Index Scan in SQL Server

1.Clustered Index Scan ✅ What it is: A Clustered Index Scan means SQL Server is scanning every row of the entire table,  essentially performing a "table scan" because the clustered index is the table itself.  📌 When it happens: No WHERE clause or very broad filter (low selectivity). Join/filter columns aren’t indexed selectively. Query needs most or all columns (covering queries). 🧠 Performance Insight: Can be expensive for large tables. Usually appears when SQL Server can’t seek and needs to read all data. Example:    Table: CREATE TABLE dbo.Sales (     SaleID INT NOT NULL IDENTITY,     SaleDate DATE NOT NULL,     Quantity INT NOT NULL, PRIMARY KEY (SaleID) ) Query: SELECT * FROM dbo.Sales WHERE  SaleDate  BETWEEN '2025-02-04' AND '2025-02-10' 2. Index Scan (Non-Clustered) ✅ What it is: A Non-Clustered Index Scan scans all rows in a specific non-clustered index( not the full table) 📌 When it happens: The query filters on a ...

SQL Server script Error: Insufficient result space to convert uniqueidentifier value to char.

Error:    G etting below error while trying to copy data from one table to another: Msg 8170, Level 16, State 2, Line 1004  Insufficient result space to convert uniqueidentifier value to char.   Fix: UserID column which would be having Unique identifier data require more space (36 character). Size is specified as 15 here. To fix it just specify 36 as varchar length or specify Uniqueidentifier as data type for UserID  column.