For Programmers: Free Programming Magazines  


Home > Archive > SQL Server Programming > October 2005 > Check constraints









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Check constraints
Niclas

2005-10-30, 7:57 am

Hi,

If I have three columns called 'userid' 'event' and 'result' and only allow
one result row per event and userID. I.e. each user can only have one result
per event.

How would a constraint expression look like for this ?

Nic


Tony Rogerson

2005-10-30, 7:57 am

alter table <yourtable> add constraint uk_<yourtable>_event_userid unique
( event, userid )

That will only allow one row to have the same event and userid.

Tony.

--
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials


"Niclas" <lindblom_niclas@hotmail.com> wrote in message
news:edSyoJV3FHA.3292@tk2msftngp13.phx.gbl...
> Hi,
>
> If I have three columns called 'userid' 'event' and 'result' and only
> allow one result row per event and userID. I.e. each user can only have
> one result per event.
>
> How would a constraint expression look like for this ?
>
> Nic
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com