0

I have a table structure with several 0 to 1 relationships.

1 Resource can have

0 to 1 Temporary Codes
0 to 1 Permanent Codes OR 0 to 1 Store Credits

I'm looking for a way to ensure at the database level that an entry cannot exist in both the permanent code table AND the store credit table. (it should produce an error - as if a duplicate key were being added)

Can anyone think of a design that would ensure this? Or should I use a stored procedure?

Any advice would be appreciated!

edit: To be clear - what I want to ensure is that if I try to insert an entry into Permanent Codes AND Store Credits - this would violate some kind of database rule (Produce an error). In other words, it should be impossible to have both.

  • See [How to create multiple one to one's](http://stackoverflow.com/a/9178524/533120). – Branko Dimitrijevic May 08 '14 at 17:16
  • 1
    Why not use the same column for all? Treat like a bitflag setup. Where 1's can be temp codes, 2's can be permanent codes, and 4's to be store credits. So `b'000` would be all 0's, and `b'100` be Store credit. – Sunny Patel May 08 '14 at 17:16

0 Answers0