What is the difference between clustered and non-clustered indexes?

Clustered indexes are physical structures that determine the order in which data is stored in a table. They are used to improve the speed of data retrieval from the table. For example, if you have a table of customer orders, you can create a clustered index on the order date field to quickly locate orders within a certain date range.

Non-clustered indexes are logical structures that create a separate copy of the data from the table. They are used to improve the speed of data retrieval from the table. For example, if you have a table of customer orders, you can create a non-clustered index on the customer name field to quickly locate orders by customer name.

How does SQL Server use indexes?

SQL Server uses indexes to quickly locate data without having to search every row in a table every time a query is run. Indexes can be created using one or more columns of a table, providing the basis for both rapid random lookups and efficient access of ordered records.

For example, if you had a table of customer orders, you could create an index on the customer name and order date columns. This would allow you to quickly find all orders for a particular customer, or all orders placed on a particular date.