Re: A strange relationship...

From: Joe Celko <71062.1056_at_compuserve.com>
Date: 2000/07/23
Message-ID: <8lf675$2ni$1_at_nnrp1.deja.com>#1/1


>> I have an E-R schema, similar to this, where «» hold the primary
key: <<

Please post DDL instead

CREATE TABLE Pubs
(home_id INTEGER NOT NULL PRIMARY KEY
 address CHAR(30) NOT NULL,
 town CHAR(30) NOT NULL);

CREATE TABLE Personnel
(emp_id INTEGER NOT NULL PRIMARY KEY
 name CHAR(30) NOT NULL,
 role CHAR(10) NOT NULL REFERENCES ??
 hairstyle CHAR(10) NOT NULL CHECK (hairstyle IN (..),  ...);

CREATE TABLE Telephones
(phone_number DECIMAL(10,0) NOT NULL PRIMARY KEY,  phone_type CHAR (3) NOT NULL

            CHECK (phone_type IN ('fax', 'cel', ...)));

>> Now, each Pub has one or more phone numbers, just like every employee
may have (one-to-N). How can I realize such a relation? <<

CREATE TABLE PubPhones
(home_id INTEGER NOT NULL

         REFERENCES Pubs(home_id)
         ON DELETE CASCADE
         ON UPDATE CASCADE,
 phone_number DECIMAL(10,0) NOT NULL
         REFERENCES Telephones(phone_number)
         ON DELETE CASCADE
         ON UPDATE CASCADE,

 PRIMARY KEY (home_id, phone_number));

Where di you get the idea that a key has to be only one column?

--CELKO--
Joe Celko, SQL and Database Consultant
When posting, inclusion of SQL (CREATE TABLE ..., INSERT ..., etc) which can be cut and pasted into Query Analyzer is appreciated.

Sent via Deja.com http://www.deja.com/
Before you buy. Received on Sun Jul 23 2000 - 00:00:00 CEST

Original text of this message