sql - What is the best way to tie 1 table to many tables -


I have a table, call it table A

This table will be linked to several tables, and ideally In database connection relations (many -1) (table-table-b) (many -1) (table-table-c) will be implemented ... etc.

I have the solution table in the "B "All foreign keys of type are placed in the table with a" Type "field (which contains a word version whose relationship is applied). Although I think there should be a better way. What would you do?

I appreciate any further advice in this.

This is a completely acceptable approach - foreign key is actually modeling multiple-to-one relationships The right way is. Generally, you can not say that you want to make a solution "better"; Rather, you should have a specific goal in mind. Better, lesser implementation, less memory, whatever is better than this is that you have a special use case for which you want to adapt.

Edit : Your question is now more clear that you edited it. If I understand correctly, then you feel that your current implementation is inefficient as one of the items in your table can be attached to another item, this table can be from C, Tablec, etc.

If this is correct, then I can do that in the table A, the foreign key is enforced as both an ID and a table name, rather than a new one for each new type of object Instead of creating the columns that you want to add to your system. Of course, this prevents you from changing table names, so for a more robust solution, unique ID mapping will be required for other types of objects (stored in table names). Then the table A will have the foreign key item_id and object_type_id , and you can retrieve the object by looking at object_types object_type_id table name


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -