Should I always design around foreign keys? -


For example, I have the tag lookup table that contains 3 different types of table tags (ObjectTaps) tags. Each has the tag, but they are not shared.

So I could do it

Tagged | Object type ObjectId |

And when I join the table together, I used to filter it by object type even before joining it.

Now I know that this will break the ability to do a foreign key. The ObjectId column can be one of the three tables.

The question is .. Is this a terrible thing? If so, why?

The second option is to create a lookup table for each object, unless there is a better method. Do not think about the foreign key, think about whether you have the integrity referenced at the database level. Want to apply. Without the relevant integrity enforced by RDBMS, you have to implement yourself in your application, or to do something else, you have to go out of your way to write the constraints of complex database, RDBMS already gives you as a foreign key is.

In practice, however, you are not going to get a good reason to store three conceptual tables in a large table. It is not a good idea to store more than one table data in the same table because they have the same columns, they have the same schema, but they are not the same table.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -