Andrius
Andrius

Reputation: 981

No value repetition in same column

I have table called Dates. It contains foreign key to another table and a date ( 2 columns in total). It can contain same foreign values but one foreign value cannot contain same dates (only different dates). For example.

FKey    |   Date
_____________________
1       | 13-01-2013
1       | 14-01-2013
2       | 14-01-2013
1       | 14-01-2013 <- this is wrong since it already contains this value above 
                        with same foreign key ( it should not be inserted)

I think i should do it by creating assertion to table using (CHECK clause) but i don't know how. Any ideas ?

Thank you

Upvotes: 0

Views: 71

Answers (1)

Robin Green
Robin Green

Reputation: 33063

ALTER TABLE Dates ADD CONSTRAINT u_Dates UNIQUE (FKey, Date);

Upvotes: 3

Related Questions