?
Solved

Get all unique constraints in database

Posted on 2013-06-06
3
Medium Priority
?
279 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 66

Accepted Solution

by:
Jim Horn earned 668 total points
ID: 39225556
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 668 total points
ID: 39225567
0
 
LVL 19

Assisted Solution

by:Bhavesh Shah
Bhavesh Shah earned 664 total points
ID: 39225596
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

752 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