How to Find Composite Primary Key Columns in SQL Server

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.

What is a composite primary key?

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.

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Trust DCAC with your data

Your data systems may be treading water today, but are they prepared for the next phase of your business growth?

Denny Cherry & Associates Consulting
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.