Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nzwim-00082J-O9 for pgsql-general@arkaria.postgresql.org; Sat, 11 Jun 2022 08:43:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nzwil-0006v4-AN for pgsql-general@arkaria.postgresql.org; Sat, 11 Jun 2022 08:43:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nzwik-0006uu-Sy for pgsql-general@lists.postgresql.org; Sat, 11 Jun 2022 08:43:50 +0000 Received: from srv01.teladesign.ie ([2001:41c9:1:41d::10]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nzwih-0006Zh-Tx for pgsql-general@lists.postgresql.org; Sat, 11 Jun 2022 08:43:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rodonnell.ie; s=exim; h=Content-Type:MIME-Version:Subject:References: In-Reply-To:Message-ID:Date:To:From:Content-Transfer-Encoding:Sender:Reply-To :Cc:Content-ID:Content-Description:Resent-Message-ID; bh=V6YXCqlPtZtp3Qwzqwvkc1lRp7gYvWM9zpbcF7J9hLk=; b=NimHNgN7/KFATMfAku07raU4gb x9gE07N7ogt9husVXix94AeuQzmhc7Nw1atntYqFW2fjzr7qurux48Gi5V3rgimDKe0AVdUKx2heP smDvsUeKJerfdluJgWJYj/ictVenvyjHRofZCPCyUMKo8gGaRV9dEpT3WJjhPsoOyD08=; Received: from [85.134.236.246] (helo=[192.168.15.21]) by srv01.teladesign.ie with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nzwie-0004Z8-Bo; Sat, 11 Jun 2022 09:43:44 +0100 From: "Ray O'Donnell" To: Rino Mardo , Date: Sat, 11 Jun 2022 09:43:46 +0100 Message-ID: <18151eefdd0.2834.f9dd809031fc0469edf0bbbf79c1d468@rodonnell.ie> In-Reply-To: References: User-Agent: AquaMail/1.36.0 (build: 103600147) Subject: Re: newbie db design question MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="18151eefe60606528343fa8f3b" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --18151eefe60606528343fa8f3b Content-Type: text/plain; format=flowed; charset="us-ascii" Content-Transfer-Encoding: 8bit On 11 June 2022 08:05:41 Rino Mardo wrote: > hello! > > 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 Hi there, "serial" isn't a real type - it's just a shortcut for "integer not null default nextval(....)". Read about it here: https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-SERIAL So the supplier_id column in the first table should be of type "integer". > > supplier_id serial primary key references supplier > > but it won't allow multiple primary key. > > how then to proceed? You need a foreign key.... add this to the first table: constraint foreign key (supplier_id) references supplier(supplier_id) I hope this helps. Ray. > > > regards, --18151eefe60606528343fa8f3b Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
On 11 June 2022 08:05:41= Rino Mardo <rino19ny@gmail.com> wrote:
hello!

reall= y noob question here. i have this experimental database design:

create table prod= ucts (
product_id serial primary key,
description text,
supplier_id????) ;
=

create table supplier (
=
supplier_id serial primary key,
de= scription text) ;


the products table should be linked to the supplier t= able 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

Hi there,

"serial" isn't a real type - it's just a shortcut for "integer no= t null default nextval(....)". Read about it here:
<= br>
So the supplier_id column in the first table shoul= d be of type "integer".


supplier_id serial primary key references supplier

but it won't allow multipl= e primary key.

how then = to proceed? 


You need = a foreign key.... add this to the first table:

<= /div>
constraint <constraint name> foreign key (supp= lier_id) references supplier(supplier_id)

=
I hope this helps.

Ray.




regards,





--18151eefe60606528343fa8f3b--