zingmatter
04-18-2007, 04:39 AM
We're rebuilding our site, including the database. We want to improve the database by introducing foreign key constraints to all our tables.
The argument brewing amongst the developers is to do with delete of certain records. Strictly speaking we don't actually want to delete the record but just effectively remove it from "display". Currently we've been doing this (for a small number of record types) by negating the foreign key, i.e. a record associated with a certain userid 12345 (the foreign key) gets changed to -12345. That way, if we need to restore the record we can simply look for the negative version of this key. But this would break a fk constraint and effectively denormalises the database.
I would prefer to have a boolean "active" field on the table so that we just set this to false in order to acheive the same effect. The downside is more server load and queries will always have to include "... AND Active = 1 .." .
Does anyone have any experience of this kind of thing? Is the method of "denormalising" by negating a fk field such a bad thing? Are there significant benefits from keeping the database as pure as the driven snow in a practical sense (not just in the minds of purists and academics)
Any thoughts greatly appreciated. Thanks.
The argument brewing amongst the developers is to do with delete of certain records. Strictly speaking we don't actually want to delete the record but just effectively remove it from "display". Currently we've been doing this (for a small number of record types) by negating the foreign key, i.e. a record associated with a certain userid 12345 (the foreign key) gets changed to -12345. That way, if we need to restore the record we can simply look for the negative version of this key. But this would break a fk constraint and effectively denormalises the database.
I would prefer to have a boolean "active" field on the table so that we just set this to false in order to acheive the same effect. The downside is more server load and queries will always have to include "... AND Active = 1 .." .
Does anyone have any experience of this kind of thing? Is the method of "denormalising" by negating a fk field such a bad thing? Are there significant benefits from keeping the database as pure as the driven snow in a practical sense (not just in the minds of purists and academics)
Any thoughts greatly appreciated. Thanks.