Solved

Get all unique constraints in database

Posted on 2013-06-06
3
255 Views
Last Modified: 2013-06-20
I'd like to get all unique constraints in database for all tables) and like to get result in below format:

SchemaName, TableName, UniqueConstraintName, ColumnName

How to achieve it? Please assist.
0
Comment
Question by:Easwaran Paramasivam
3 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 167 total points
Comment Utility
Here's a start...

SELECT
      OBJECT_NAME(OBJECT_ID) AS NameofConstraint,
      SCHEMA_NAME(schema_id) AS SchemaName,
      OBJECT_NAME(parent_object_id) AS TableName,
type_desc AS ConstraintType
FROM sys.objects
WHERE type_desc LIKE '%CONSTRAINT'
GO
0
 
LVL 10

Assisted Solution

by:Asim Nazir
Asim Nazir earned 167 total points
Comment Utility
0
 
LVL 19

Assisted Solution

by:Bhavesh Shah
Bhavesh Shah earned 166 total points
Comment Utility
Same query given by jimhorn

SELECT 
      OBJECT_NAME(OBJECT_ID) AS NameofConstraint,
      SCHEMA_NAME(schema_id) AS SchemaName,
      OBJECT_NAME(parent_object_id) AS TableName,
type_desc AS ConstraintType
FROM sys.objects
WHERE type_desc in ('PRIMARY_KEY_CONSTRAINT','UNIQUE_CONSTRAINT')

Open in new window

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now