views:

47

answers:

1

There are two ways to create a constraint,

Method A:

ALTER TABLE dbo.<tablename> ADD CONSTRAINT
<namingconventionconstraint> UNIQUE NONCLUSTERED
(
<columnname>

Method B:

CREATE UNIQUE NONCLUSTERED INDEX
<namingconventionconstraint> ON dbo.<tablename>
(
<columnname>
) ON [PRIMARY]

However, it appears that these constraints need to be dropped using a method that is dependent on how they were created (Drop constraint vs drop index). Is there a way to determine what method the constraint was created other than trying a method and seeing if it fails? I know you can have SQL Server create a drop script for you but I'm looking for a query of some sort.

+8  A: 

This is why you can have the same index name for many table, but a table level unique constraint has to be database/schema unique

gbn
The database I am currently dealing with this issue in has both unique constraints and unique indexes prefixed with UQ, will it still be different in sys.objects?**edit** I realized thats a poorly worded question. If I look at the indexes folder under each table in SQL Server Management Studio they are prefixed with UQ. Will their type still be different when looking at sys.objects?
stocherilac
@stocherilac: A unique index entry (method B) won't exist in sys.objects
gbn
@gbn: okay thank you!
stocherilac