dbTalk Databases Forums  

How to query system tables to get unique constraints

microsoft.public.sqlserver.programming microsoft.public.sqlserver.programming


Discuss How to query system tables to get unique constraints in the microsoft.public.sqlserver.programming forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
nima
 
Posts: n/a

Default How to query system tables to get unique constraints - 06-03-2004 , 08:31 PM






Hello everyone

I am trying to write a query to get a list of unique constraints in my database. I want the constraint name, table name, and column names. I get everything fine except for the column names. sysconstraints' colid column has zeros instead of values. How can I get a list of the columns used in my unique constraints

Thanks a bunch in advance for your help.

Reply With Quote
  #2  
Old   
Hari Prasad
 
Posts: n/a

Default Re: How to query system tables to get unique constraints - 06-03-2004 , 08:49 PM






Hi,

Use the below Query:-

select a.table_name, b.column_name, a.constraint_name from
information_schema.TABLE_CONSTRAINTS
a,information_schema.CONSTRAINT_COLUMN_USAGE b
where a.constraint_name=b.constraint_name
and a.table_name=b.table_name
and constraint_type='UNIQUE'

Thanks
Hari
MCDBA


"nima" <anonymous (AT) discussions (DOT) microsoft.com> wrote

Quote:
Hello everyone,

I am trying to write a query to get a list of unique constraints in my
database. I want the constraint name, table name, and column names. I get
everything fine except for the column names. sysconstraints' colid column
has zeros instead of values. How can I get a list of the columns used in my
unique constraints?
Quote:
Thanks a bunch in advance for your help.



Reply With Quote
  #3  
Old   
nima
 
Posts: n/a

Default Re: How to query system tables to get unique constraints - 06-04-2004 , 12:11 PM



Thanks Hari

This is exactly what I wanted but I was not able to figure it out. I very much apreciate your help.

Nima

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.