Home > SQL > Get all Table name and Primary Key constraint in a database

Get all Table name and Primary Key constraint in a database

Today i got modified database from customer, they asked to validate the database and include in our project. While am validating i came to know that some of the table name where changed. so i tried to find out the changed table name, at that time Primary key constrain give hand to find out those table.

while am surffing in google i got the Query as below

SELECT i.name AS IndexName,
OBJECT_NAME(ic.OBJECT_ID) AS TableName,
COL_NAME(ic.OBJECT_ID,ic.column_id) AS ColumnName
FROM sys.indexes AS i
INNER JOIN sys.index_columns AS ic
ON i.OBJECT_ID = ic.OBJECT_ID
AND i.index_id = ic.index_id
WHERE i.is_primary_key = 1

Above Query gives me Constraint name and Table name. Thanks to sqlauthority.com

Advertisements
Categories: SQL
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: