开发者

Enforce Unique on multiple sets of same data?

What i want to do is this:

a, b - valid.

a, b - valid.

a, c - invalid

f, b - invalid.

So this means the database will allow the same combination of values to exists multiple times but will not allow any other combo to use those values. So it is like a Unique on a combination set. My usecase is i have a group_id and group_name in the table. I dont want peple to mess up the group_name for an ID. So if the first ID of 2 has group_name as 'apple' 开发者_如何学Pythonthen all IDs with 2 must be 'apple' and should throw error if 'banana' is entered.

One way is i use a 2nd table and normalize the data but i cant do that here, need to use it denormalized. So is there anyway to enforce this check?

Thanks


maybe validate during insert and update trigger.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜