I have 2 tables that have a 1-M relationship:
TABLE foo
- foo_id (PK)
- foobar_id
- value
TABLE bar
- bar_id (PK)
- foo_id (FK to foo.foo_id)
- foobar_id
- value
I want to make sure foo.foobar_id and foo.value are unique, and thus want to make them a composite key. If I do that, then I can probably get rid of foo.foo_id. And if I do that, how do I relate foo and bar?
I also want bar.foo_id and bar.foobar_id to be unique, but will run into problems if I delete foo.foo_id.
Suggestions on how to model this?
Just create an unique index that covers both fields. In this case only unique pairs will be allowed.