Search code examples
sqldatabasedatabase-schemareferential-integrityschema-design

When is referential integrity not appropriate?


I understand the need to have referential integrity for limiting specific values on entry or possibly preventing them from removal upon a request of deletion. However, I am unclear as to a valid use case which would exclude this mechanism from always being used.

I guess this would fall into several sub-questions:

  1. When is referential integrity not appropriate?
  2. Is it appropriate to have fields containing multiple and/or possibly incomplete subsets of a foreign key's list?
  3. Typically, should this be a schema structure design decision or an interface design decision? (Or possibly neither or both)

Thoughts?


Solution

  • When is referential integrity not appropriate?

    Referential intergrity if typically not used on Data Warehouses where the data is a read only copy of a transactional datbase. Another example of when you'd not need RI is when you want to log information which includes row ids; maintaining referential integrity for a read-only log table is a waste of database overhead.

    Is it appropriate to have fields containing multiple and/or possibly incomplete subsets of a foreign key's list?

    Sometimes you care more about capturing data than data quality. Imagine you are aggregating a large amount of data from disparate systems which each in their own right suffer from data quality issues. Sometimes you are after the greater good of data quality and having everything in one place even with broken keys etc. represents a starting point for moving towards true data quality. It's not ideal, but it does happen as the beenfits could outweigh the tradeoffs.

    Typically, should this be a schema structure design decision or an interface design decision? (Or possibly neither or both)

    Everything about systems development is centered around information security, and a key element of that is data integrity. The database structure should lean towards enforcing these things when possible, however you often are not dealing with modern database systems. Sometimes your data source is an old school AS400 with long-antiquated apps. Sometimes you have to build a data and business layer which provide for data integrity.

    Just my thoughts.