There is nothing in the GetSchemaTable on SqlConnection call that will let you understand this.
It might seem that you can use the value of the IsKey column, which should return true for everything, which helps to uniquely identify the record in the table. However, from the documentation for the IsKey column (my selection):
true: a column is one of many columns in a set of rows that were taken together that uniquely identify a row. A set of columns with IsKey set to true should uniquely identify a row in a set of rows. There is no requirement that this set of columns is a minimum set of columns. This set of columns can be formed from a base table primary key, a unique constraint, or a unique index .
Because of this, you cannot guarantee that it contributes to the primary key per se.
Now, if you only need to uniquely identify the string, then IsKey will be fine, since the primary key is not always a way to uniquely identify the string (for example, you can have natural identifiers with a unique index), even if you have a primary key and a unique index with other columns, the values โโin all of these columns in combination will always be unique.
However, if you need to look at the columns that make up the primary key, then GetSchemaTable will not give you the necessary information. Most likely, you can simply call the sp_pkeys system stored procedure to find the column names that contribute to the creation of the primary key.
casperOne
source share