Search code examples
sql-serversql-server-2012query-performancesql-server-performance

Primay key non-clustered (composite key) and clustered index on different column in same table?


I am using SQL Server 2012 and for one of the table I see it has created primary key non-clustered (composite key) and clustered index on different column? Can somebody help me to understand what will happen in this situation?

  1. Does this going to degrade performance for DML operations? If yes how to measure it?
  2. Will this be causing locking/blocking/deadlocks for this table when performing DML operation during concurrency ?

Note: this table has a huge number of records in it ~10 million


Solution

  • One common scenario where you might end up with a primary key which is a non clustered composite key is a junction table. A junction table mainly exists to store a relationship between two primary key values from other tables. A simple example would be storing say relationships between students and the courses they take. As such, the primary (unique) key in such a table would actually be the combination of the two foreign key columns. That being said, there can still be a clustered index on some other column. There is nothing at all out of the ordinary here, assuming such a table falls in line with your design intentions.