Re: Table design issue....

From: "Josh Berkus" <josh(at)agliodbs(dot)com>
To: pierre(at)kahuna(dot)versions(dot)com, pgsql-sql(at)postgresql(dot)org
Subject: Re: Table design issue....
Date: 2001-06-11 17:44:01
Message-ID: web-70284@davinci.ethosmedia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Pierre,

> Ideas? Comments? Suggestions? Am I being crazy?

Yes. To be blunt, you've picked one of the worst possible database
designs for any useful purpose. This is, however, a common mistake as
far too many books and training courses teach how to write SQL without
teaching how to design a database.

What you really want is something like this:

CREATE TABLE tables (
tableid CHAR(1) NOT NULL PRIMARY KEY
);

CREATE TABLE attributes (
tableid CHAR(1) NOT NULL REFERENCES tables(tableid),
attributeid CHAR(1) NOT NULL,
CONSTRAINT tab_attr_PK PRIMARY KEY (tableid, attributeid)
);

This makes your select statement possible:
SELECT tableid FROM attributes WHERE attributeid = 'C'
GROUP BY tableid ORDER BY tableid;

If your application requirements are more complicated than this, you
need to either: a) hire a relational design expert, or b) become one.
Books I'd recommend for the latter are Database Design for Mere Mortals
and Practical Issues in Database Design (F. Pascal).

-Josh Berkus

______AGLIO DATABASE SOLUTIONS___________________________
Josh Berkus
Complete information technology josh(at)agliodbs(dot)com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Alex Pilosov 2001-06-11 17:49:40 Re: finding a maximum or minimum sum
Previous Message pierre 2001-06-11 17:28:03 Re: Table design issue....