Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 6A9A99FB1B9 for ; Mon, 8 Jan 2007 17:54:47 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 64027-06 for ; Mon, 8 Jan 2007 17:54:36 -0400 (AST) X-Greylist: delayed 00:15:03.790833 by SQLgrey-1.7.4 Received: from gatekeeper.daycos.com (outbound.daycos.com [204.26.70.70]) by postgresql.org (Postfix) with ESMTP id 096A99FA6B0 for ; Mon, 8 Jan 2007 17:54:38 -0400 (AST) Received: by gatekeeper.daycos.com with Internet Mail Service (5.5.2653.19) id ; Mon, 8 Jan 2007 15:39:31 -0600 Message-ID: <031936836C46D611BB1B00508BE7345D04DC1B78@gatekeeper.daycos.com> From: Curtis Scheer To: pgsql-sql@postgresql.org Subject: Table relationships Date: Mon, 8 Jan 2007 15:39:31 -0600 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C7336D.7B073430" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/16 X-Sequence-Number: 27168 This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01C7336D.7B073430 Content-Type: text/plain I'm having trouble determining the best way to implement the following scenario for a customer database. Given the following tables what is the best way to link an address table to both the "Master" and the "Detail" tables. Basically there can be many addresses for each customermaster record and also many address for each customerdetail record. Will this require two many-to-many tables? Or is there a better solution I am missing? Is there any easy way to build in a "Default" address or would that be something to do logically in client code? Thanks, Curtis CREATE TABLE testing.customermaster ( customermasterid int4 NOT NULL DEFAULT nextval('testing.customermatser_customermasterid_seq'::regclass), name varchar NOT NULL, description varchar, ) CREATE TABLE testing.customerdetail ( customerdetailid int4 NOT NULL, customermasterid int4 NOT NULL, notes varchar, closed bool, customerdepartment varchar(3), ) CREATE TABLE address ( addressid int4, name varchar(40), addr varchar, city varchar(42), st varchar(2), zip varchar(30) ) Possible many-to-many tables CREATE TABLE customermaster_address ( addressid int4, customermasterid int4 ) CREATE TABLE customerdetail _address ( addressid int4, customerdetailid int4 ) ------_=_NextPart_001_01C7336D.7B073430 Content-Type: text/html Content-Transfer-Encoding: quoted-printable

I’m having trouble determining the best way to implement the following scenario for a customer = database.

 

Given the following tables what is the best way to = link an address table to both the “Master” and the = “Detail” tables. Basically there can be many addresses for each customermaster = record and also many address for each customerdetail record. Will this require = two many-to-many tables? Or is there a better solution I am missing? Is = there any easy way to build in a “Default” address or would that be = something to do logically in client code?

 

Thanks,

Curtis

 

CREATE TABLE = testing.customermaster

(

  customermasterid int4 NOT NULL DEFAULT nextval('testing.customermatser_customermasterid_seq'::regclass),

  name varchar NOT = NULL,

  description = varchar,

)

 

CREATE TABLE = testing.customerdetail

(

  customerdetailid int4 NOT = NULL,

  customermasterid int4 NOT = NULL,

  notes varchar,

  closed bool,

  customerdepartment = varchar(3),

)

 

CREATE TABLE address

(

  addressid int4,

  name = varchar(40),

  addr varchar,

  city = varchar(42),

  st varchar(2),

  zip varchar(30)

)

 

 

Possible many-to-many tables

CREATE TABLE = customermaster_address

(

  addressid int4,

 customermasterid = int4

)

 

CREATE TABLE customerdetail = _address

(

  addressid int4,

 customerdetailid = int4

)

 

------_=_NextPart_001_01C7336D.7B073430--