I’m working with a database with poor design. Most tables do have a PK, but FK’s do not exist. This makes it difficult to visualize the relationships between the tables. This leads me to wonder, why does SQL let us join tables with no constraint? If I am going to join Table A on Table B with EmployeeId shouldn’t the knee jerk reaction be to setup a FK?
Share
Because constraints are optional.
I agree that not using constraints is usually a bad idea, but in general, one doesn’t have to have constraints for a valid database design to be created.
Some applications require that no constraints are used say for a hard delete of a “current” record that still has an audit trail table (which some reports will join on).
In such a scenario, not being able to join would hamper flexibility and the ability to use the DB.
This of course leave aside the fact that many databases are created by people (business or developers) that don’t know about or care about referential integrity.