Order of records stored in SQL Server table
By Santhosh N
This explains how (in which order) the SQL Server stores the records in the table.
Most of us assume the records are stored in the order as they were entered in the
table in SQL Server. But, the records are stored on the basis of the clustered
index created on the table.
If the CLUSTERED index is created on any column and using any sorting keyword (for
example DESC) then the records are stored in the descending order of the column
on which clustered index is created.
Ex: Let us assume we have created a clustered index on hiredate column in emp table
as below:
CREATE CLUSTERED INDEX hiredate ON emp(hiredate DESC)
Now the records are stored in the descending order of the hiredate column with latest
hire date records being on top.
Related FAQs
This explains how to set DEADLOCK_PRIORITY in SQL Server and its benefits in doing so.
This explains how to use TEMP tables in the SELECT query for better query performance.
This explains the advanced query tuning concepts of the SQL Server in terms of using joins
This explains the QUERY_GOVERNOR_COST_LIMIT option for controlling long running queries in the SQL Server.
This explains where to have a loop if at all required to have one to get the desired result from the database.
This explains how to approach and check for bottlenecks in the SQL queries.
Order of records stored in SQL Server table (1303 Views)