Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
0 like 0 dislike
1.2k views
in SQL Queries by 21 20 26

I created a new table and set ID as a primary key and in the folder index I found PK__NewEmp__3214EC27634FE916 clustered

I want to create another Index on Salary column is it possible? Also, I want to know What the advantages of an index in SQL Server and what's the difference between clustered index and non-clustered index?

clustered index VS non-clustered index in SQL Server


1 Answer

0 like 0 dislike
by 24 26 40

What're Indexes in SQL Server?

Indexes are used to retrieve data from the database more quickly. The users cannot see the indexes, they are just used to speed up searches/queries.

Clustered Index Vs non-clustered Index

Clustered index: determine the physical order of data.
The table can have only one Cluster index, and Cluster Index can be one-column or two-column

Note: If you add a primary key for a table its automatically becomes a clustered index.

Non clustered indexes: have a structure separate from the data rows.
A non clustered index contains the non clustered index key values and each key-value entry has a pointer to the data row that contains the key value.

Note You can create many nonclustered indexes

To Create Nonclustered for the salary table, you can use this query:

Create Nonclustered Index IX_TableName_Salary
on TableName (Salary)

For more details, you can also see Clustered and Nonclustered Indexes

If you don’t ask, the answer is always NO!
...