Re: Database design?

From: "Aasmund Midttun Godal" <postgresql(at)envisity(dot)com>
To: johnny(at)halfahead(dot)dk
Cc: pgsql-general(at)postgresql(dot)org, rshepard(at)appl-ecosys(dot)com
Subject: Re: Database design?
Date: 2001-10-23 21:46:27
Message-ID: 20011023214628.27236.qmail@ns.krot.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Err. CREATE TABLE entities that is.
On Tue, 23 Oct 2001 16:26:43 GMT, "Aasmund Midttun Godal" <postgresql(at)envisity(dot)com> wrote:
> Ok let me try to explain how I would do it:
>
> CREATE TABLE languages (
> "language" TEXT PRIMARY KEY,
> );
>
> CREATE SEQUENCE description_seq;
>
> CREATE TABLE descriptions (
> id PRIMARY KEY, -- You could make this default
> -- curval('description_seq')
> -- if you are absolutely 100% sure only one person inserts at the time.
> description TEXT NOT NULL,
> language REFERENCES languages NOT NULL,
> UNIQUE(id, language)
> );
>
> CREATE TABLE authors (
> id DEFAULT nextval('decription_seq') PRIMARY KEY,
> firstname TEXT,
> lastname TEXT NOT NULL,
> unique(firstname, lastname)
> );
>
> CREATE TABLE books (
> id DEFAULT nextval('decription_seq') PRIMARY KEY,
> title,
> author REFERENCES authors NOT NULL,
> book bytea,
> unique(title, author)
> );
>
> This is the basic structure.
>
> Now if you like you can have a map table - although I am not sure I would.
>
> CREATE TABLE languages (
> "language" TEXT PRIMARY KEY,
> );
>
> CREATE SEQUENCE description_seq;
>
> CREATE TABLE entities (
> id DEFAULT nextval('decription_seq') PRIMARY KEY
> );
>
> CREATE TABLE descriptions (
> id REFERENCES entities PRIMARY KEY, -- You could make this default
> -- curval('description_seq')
> -- if you are absolutely 100% sure only one person inserts at the time.
> description TEXT NOT NULL,
> language REFERENCES languages NOT NULL,
> UNIQUE(id, language)
> );
>
> CREATE TABLE authors (
> id REFERENCES entities PRIMARY KEY,
> firstname TEXT,
> lastname TEXT NOT NULL,
> unique(firstname, lastname)
> );
>
> CREATE TABLE books (
> id REFERENCES entities PRIMARY KEY,
> title,
> author REFERENCES authors NOT NULL,
> book bytea,
> unique(title, author)
> );
>
> On Tue, 23 Oct 2001 06:47:30 -0700 (PDT), Rich Shepard <rshepard(at)appl-ecosys(dot)com> wrote:
>
> Aasmund Midttun Godal
>
> aasmund(at)godal(dot)com - http://www.godal.com/
> +47 40 45 20 46
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html

Aasmund Midttun Godal

aasmund(at)godal(dot)com - http://www.godal.com/
+47 40 45 20 46

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Gould 2001-10-23 21:51:02 Re: help w/ query
Previous Message Ernesto Baschny 2001-10-23 21:27:42 Re: oid not "UNIQUE" for use as FOREIGN KEY?