开发者

Declarative integrity constraint between rows without pivot

开发者 https://www.devze.com 2023-02-18 16:51 出处:网络
Merged with Declarative integrity constraint between rows without pivot. I have a situation like the following join table:
Merged with Declarative integrity constraint between rows without pivot.

I have a situation like the following join table:

A_ID  B_ID
1     27
1     314
1     5

I need to put a constraint on the table that will prevent a duplicate group from being entered. In other words:

A_ID  B_ID
2     27
2     314
2     5

should fail, but

A_ID  B_ID
3     27
3     314

should succeed, because it's a distinct group.

The 2 ways I've thought of are:

  1. Pivot the table in a materialize view based upon the order and put a unique key on the pivot fields. I don't like this because in Oracle I have to limit the number of rows in a group because of both the pivoting rules, and the 32-column index limitation (thought of a way around this second problem, but still).
  2. Create some unique hash value on the combination of the B_IDs and make that unique. Maybe I'm not enough of a mathematician, but I can't think of a way to do this that doesn't limit the number of values that I can use for B_ID.

I feel like there's something obvious I'm missing here, like I could just add some sort of an ordering colum开发者_Go百科n and set a different unique key, but I've done quite a bit of reading and haven't come up with anything. It might also be that the data model I inherited is flawed, but I can't think of anything that would give me similar flexibility.

0

精彩评论

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