[GLLUG] Is there any sane reason to do this? (Database question.)

Martin A. Brooks martin at hinterlands.org
Wed Oct 8 07:26:47 UTC 2014


On Tue, October 7, 2014 20:05, John Winters wrote:
> Is there a good design reason to do this?

I can sort of see why you might do this, but it's still wrong.  What
they're trying to do, I think, is provide a consistent reference date for
a set of related rows in other tables.  I would not do that in this
manner, but if I were it'd be something like:

create table dateref(
  id serial,
  d datetime with timezone default now();
);

and then use ID as a foreign key constaint for every table that needed a
date reference.   The database does the work of enforcing the integrity
and you can use things like cascading deletes to keep the whole thing
clean.







More information about the GLLUG mailing list