Search:   Dictionary All Posts
Store Your Knowledge at the Brain Bank!

Relations in Databases - Explicitly Expressed or Not is OK!

By Jamie in Lessons / Programming - MYSQL  11.10.18  (Source)
Summary - I've never created foreign keys in my database schemas and always wondered why it was necessary. Now I know why, and that it isn't necessarily necessary in most of my cases.
Some of the good points on this are maintenance of a database. If you want to delete a customer and everything he did in every table in the database, you have to go through and delete each one independently. However, you have foreign keys setup you can simply delete the user from the main table and all the other tables will also remove his data.

Though, I can see major issues with this. Say a user wants to delete his account. He may want to disappear, but the owner of the store certainly doesn't want it removed from his records every sale made to that customer.

The point of all this is this - as long as you set relationships in your code, and don't repeat information/data from one table to another, than you technically are using a database as a relational database, you just aren't specifically storing a foreign key on every table pointing out that it is relational to another.