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)
 Unique / Check Constraint?

Author  Topic 

alexjamesbrown
Starting Member

48 Posts

Posted - 2008-06-19 : 17:35:09
I have a table called tblImages with the following columns:

ImageID [int]
UserID [int]
MainImg [bit]

what i need to ensure is that only one MainImage can be = 1 (true) for each userId at any one time.

any idea what i need to do?

alex

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-20 : 00:02:26
i think you'll need a trigger to enforce this condition as making a unique constraint (UserID,MainImg) will make it impossible to have multiple records with Mainimg=0 for same UserID.
Go to Top of Page
   

- Advertisement -