Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 get column name of the unique constraint.

Author  Topic 

swarna
Starting Member

6 Posts

Posted - 2005-09-08 : 04:53:29
Hi,

I want to get the column name of the unique constraint.
I used sysobject and sysconstraint which gives me the list of uniqueconstraints but i dont have any info about which column has this unique constraint...

"select * from sysconstraints "
gives me "colid" as "0" for unique constraint which makes it difficult to retrieve the column name.


Can anybody help me.


madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-08 : 05:02:20
Try this

Select t1.table_name,t2.Column_name from information_Schema.TABLE_CONSTRAINTS t1 inner join information_Schema.KEY_COLUMN_USAGE t2
on t1.table_name=T2.table_name where Constraint_Type='Unique'

you can also run

sp_help 'yourTable'


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

swarna
Starting Member

6 Posts

Posted - 2005-09-08 : 05:25:52
great...

This is working (but with some modifications)!!!!
I wasted about 2 hours trying to get some solution for it..Now i feel i should have posted it much earlier itself:-))).

Thank you very much.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-08 : 05:35:02
Well

>>This is working (but with some modifications)!!!!

What modifications did you do?
Did you supply tableName?


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

swarna
Starting Member

6 Posts

Posted - 2005-09-08 : 05:48:36
yup
supply table name
added one more condition t1.constraint_name = t2.constraint_name as data was replicating.

i dont know whether i made the correct approach but i am getting the results as i wanted.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-08 : 05:58:28
Yes. That seems good

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -