How to model a mutually exclusive relationship in sql server

Posted by littlechris on Stack Overflow See other posts from Stack Overflow or by littlechris
Published on 2010-04-24T13:43:46Z Indexed on 2010/04/24 14:13 UTC
Read the original article Hit count: 253

Filed under:
|
|

Hi,

I have to add functionality to an existing application and I've run into a data situation that I'm not sure how to model. I am being restricted to the creation of new tables and code. If I need to alter the existing structure I think my client may reject the proposal..although if its the only way to get it right this is what I will have to do.

I have an Item table that can me link to any number of tables, and these tables may increase over time. The Item can only me linked to one other table, but the record in the other table may have many items linked to it.

Examples of the tables/entities being linked to are "Person", "Vehicle", "Building", "Office". These are all separate tables.

Example of Items are "Pen", "Stapler", "Cushion", "Tyre", "A4 Paper", "Plastic Bag", "Poster", "Decoration"

For instance a "Poster" may be allocated to a "Person" or "Office" or "Building". In the future if they add a "Conference Room" table it may also be added to that.

My intital thoughts are:

Item { ID, Name }

LinkedItem { ItemID, LinkedToTableName, LinkedToID }

The LinkedToTableName field will then allow me to identify the correct table to link to in my code.

I'm not overly happy with this solution, but I can't quite think of anything else. Please help! :)

Thanks!

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server