Re: newbie db design question

From: Rino Mardo <rino19ny(at)gmail(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: newbie db design question
Date: 2022-06-12 00:20:31
Message-ID: CAGnasUV-5RdYrYF3NzxkPPxxt6bnFKNLTcLQZFNN2rGnbuY5Cw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

thank you. i have received some tips on how to approach my problem. i will
be trying them out.

On Sat, 11 Jun 2022, 5:51 pm Peter J. Holzer <hjp-pgsql(at)hjp(dot)at> wrote:

> On 2022-06-11 09:43:46 +0100, Ray O'Donnell wrote:
> > On 11 June 2022 08:05:41 Rino Mardo <rino19ny(at)gmail(dot)com> wrote:
> > really noob question here. i have this experimental database design:
> >
> > create table products (
> > product_id serial primary key,
> > description text,
> > supplier_id????) ;
> >
> > create table supplier (
> > supplier_id serial primary key,
> > description text) ;
> >
> >
> > the products table should be linked to the supplier table via
> "supplier_id"
> > column. i can't find out what would be the data type of supplier_id
> in
> > table products to do that. i tried
> >
> [...]
> >
> > how then to proceed?
> >
> >
> >
> > You need a foreign key.... add this to the first table:
> >
> > constraint <constraint name> foreign key (supplier_id) references
> supplier
> > (supplier_id)
>
> Or somewhat simpler:
>
> create table products (
> product_id serial primary key,
> description text,
> supplier_id integer references supplier
> );
>
> (You need to create supplier before doing that, of course.)
>
> hp
>
> PS: I noticed that "products" is plural and "supplier" is singular. It's
> genereally helpful to choose one convention and stick to it.
>
> --
> _ | Peter J. Holzer | Story must make more sense than reality.
> |_|_) | |
> | | | hjp(at)hjp(dot)at | -- Charles Stross, "Creative writing
> __/ | http://www.hjp.at/ | challenge!"
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Zheng Li 2022-06-12 06:46:27 Re: Support logical replication of DDLs
Previous Message Tom Lane 2022-06-11 21:25:27 Re: PG_GETARG_TEXT_PP vs PG_GETARG_TEXT_P