Unicity across multiple tables
470643Feb 24 2006 — edited Mar 1 2006Hi,
I'm currently facing a modeling situation I have never been in before. We're designing the persistence model for an application we're writing. I'm mentioning it because of object inheritance that makes sense from an OO point of view but not necessarily from a database point of view. We have objects that are different enough to be saved in different tables. However, all these objects must have a unique attribute value.
For example, milk and chocolate are different but the barcode must be unique across these two tables. I know it's not a good example for this purpose but I'm hoping it's explanatory enough ;-). I don't want to mimick the object inheritance model in the database with tables because it's quite deep and would translate into multiple joins when retrieving one object. And I also don't want to store all objects in the same table because of all these attributes that are different (also for performance and maintenance issues).
Is there a way to achieve such a thing without triggers? Can I possibly do it simply with some sort of "native" constraint?
Thanks,
Greg