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 2005 Forums
 Transact-SQL (2005)
 how can I Apply a Unique constraint in Update Quer

Author  Topic 

khufiamalik
Posting Yak Master

120 Posts

Posted - 2008-12-31 : 04:25:55
how can I Apply a Unique constraint in Update Query?

Can any one give me a sample syntax.
Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-31 : 04:29:12
unique constraint is defined on table column. Didnt understand what you mean by apply unique constraint on update. once you already define constraint, it will check value while updation and if it finds a duplicate value, it raises an error saying violation of unique constraint.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-31 : 04:30:20
alternatively, you can use an update trigger to enforce this unique value check without constraint creation, but performance will be poor.
Go to Top of Page

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2008-12-31 : 04:31:17
I think we cannot apply a unique constraint in update query

Jai Krishna
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-12-31 : 04:32:14
[code]-- Prepare sample data
DECLARE @Sample TABLE
(
i INT PRIMARY KEY
)

INSERT @Sample
SELECT 1

-- Now try to break uniqueness on i column
INSERT @Sample
SELECT 1

INSERT @Sample
SELECT 2 UNION ALL
SELECT 2[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -