Answer the question
In order to leave comments, you need to log in
How important are foreign keys in databases?
I have been working for the same company for a short time. There is a database with 1000+ tables. I was confused by the fact that despite the presence of fields with the name of the key field of another table, there is no relationship between these tables and foreign keys. In other words, a lot of foreign keys are not labeled with foreign keys. From my little experience this seems very strange and hence I have a few questions:
Answer the question
In order to leave comments, you need to log in
1. Are foreign keys always needed?
Foreign keys are needed somewhat less than always.
Loss of data consistency
Performance and locations. Here I answered a similar question in the context of postgres, other RDBMS are about the same.
1. It all depends on the organization of the project, if, for example, you have a sharded database, then no matter how you make foreign keys, or, for example, if you want to avoid data integrity checks with every data change, but do them yourself once a day. In general, foreign keys are highly desirable, but there are situations when you should not use them
2. Inconsistent data
3. In paragraph 1, he gave some examples
If the application that works with this database itself checks all connections at its application level, higher than the database. - then why not.
It's easier to manipulate tables if the DBMS doesn't bother you with its dependency control.
1. Only if you shove business logic into the DBMS
2. Data inconsistency if it is not provided by the business logic layer
3. For example, the application supports several DBMS, not all of which are able to foreign keys.
1000+ tables
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question