sqlrus.com
Finding Composite Primary Key Columns | John Morehouse
You never know when the idea for a script will make an appearance. I had to work with composite primary keys recently while working on a project for a client. More specifically, I had to create a process that would dynamically (dynamic SQL?! Say it isn't so?!) handle composite keys in an efficient manner. Usually, a primary key is just a single column that uniquely identifies a row within a table. However, a composite primary key consisting of 2 or more columns can be created. Regardless if the primary key is singular or composite, it provides identical functionality. In this particular instance, this process would perform data modifications based on the columns that composed the primary key. Thus I needed to be able to determine what columns are in the key. There is a limit to the number of columns you can have in a composite key. In SQL Server 2016 and newer, the limit is 32 columns and prior to that a primary key could have up to 16 columns. Keep in mind, neither limit is a