Groups | Blog | Home
all groups > sql server programming > april 2004 >

sql server programming : Create a constraint


Niclas Lindblom
4/13/2004 8:57:24 PM
Hi,

Being new to SQL, I need some help with the following situation.

I have a linktable that contains a column called TaskID and one called
RequestID. I would like to check on each insertion that there is not already
a taskID added for the particular RequestID. I.e. it should not be possible
to add that TaskID 2 for RequestID 3 has been completed more than once. I
assume that I need to add a Check constraint to achieve this, but I am not
sure how this statement would look like.

Any help appreciated.

Regards

Niclas

David Portas
4/13/2004 9:23:09 PM
Sounds like you need a UNIQUE constraint.

ALTER TABLE SomeTable ADD CONSTRAINT UQ_xyz UNIQUE (taskid,requestid)

--
David Portas
SQL Server MVP
--

Niclas Lindblom
4/13/2004 9:44:56 PM
Cheers !

Niclas
[quoted text, click to view]

AddThis Social Bookmark Button