Sunday, February 19, 2012

How to query for unique constraints only?

I am trying to get all the unique constraints on a certain table, but
can't seem to find the right SQL to do it.
Anyone have any pointers?
RegardsFrank Rizzo wrote:
> I am trying to get all the unique constraints on a certain table, but
> can't seem to find the right SQL to do it.
> Anyone have any pointers?
> Regards
Never mind. RTFM.
SELECT OBJECT_NAME(C.constid)
FROM sysconstraints C
WHERE C.id=OBJECT_ID('dbo.employee') AND (C.status & 0xf)=2
ORDER BY C.constid|||Hi,
Execute the below query to get all Unique constraint defined for a database
with Table name.
select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS
where Constraint_Type='Unique'
Thanks
Hari
SQL Server MVP
"Frank Rizzo" <frizzo@.notn.com> wrote in message
news:eAUEnN7zGHA.2300@.TK2MSFTNGP05.phx.gbl...
>I am trying to get all the unique constraints on a certain table, but can't
>seem to find the right SQL to do it.
> Anyone have any pointers?
> Regards|||Hari Prasad wrote:
> Hi,
> Execute the below query to get all Unique constraint defined for a databas
e
> with Table name.
>
> select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS
> where Constraint_Type='Unique'
I forgot to mention, this had to go against mssql 7.0.

>
> Thanks
> Hari
> SQL Server MVP
> "Frank Rizzo" <frizzo@.notn.com> wrote in message
> news:eAUEnN7zGHA.2300@.TK2MSFTNGP05.phx.gbl...
>|||Hi,
You could query sysconstraints Table.
You could also try;
select * from sysobjects where type='K'
This gives you both Primary and Unique constraints
Thanks
Hari
SQL Server MVP
"Frank Rizzo" <frizzo@.notn.com> wrote in message
news:%23eQJYk7zGHA.720@.TK2MSFTNGP02.phx.gbl...[vbcol=seagreen]
> Hari Prasad wrote:
> I forgot to mention, this had to go against mssql 7.0.
>

No comments:

Post a Comment