On Sat, 2003-02-22 at 12:13, Andres Ledesma wrote:
> Hi evbody...
>
> Could anybody give me an example of foreing key ..references example ?
Here is an example from one of our applications.
Regards,
Andrew.
---------------------------
-- Contact Details
---------------------------
CREATE TABLE contact (
contact_id INT4,
name TEXT,
address1 TEXT,
address2 TEXT,
city TEXT,
state TEXT,
country TEXT,
postcode TEXT,
phone TEXT, -- format is "+<contrycode>
(<areacode>) <localnumber>"
fax TEXT, -- format is "+<contrycode>
(<areacode>) <localnumber>"
email TEXT,
PRIMARY KEY ( contact_id )
);
---------------------------
-- Registrar Details
---------------------------
CREATE TABLE registrar (
registrar_id INT4,
p_contactid INT4,
d_contactid INT4,
s_contactid INT4,
registrar_name TEXT,
commenced TIMESTAMP,
PRIMARY KEY ( registrar_id ),
CONSTRAINT p_contact_of_contact FOREIGN KEY ( p_contactid ) REFERENCES
contact,
CONSTRAINT d_contact_of_contact FOREIGN KEY ( d_contactid ) REFERENCES
contact,
CONSTRAINT s_contact_of_contact FOREIGN KEY ( s_contactid ) REFERENCES
contact
);
--
---------------------------------------------------------------------
Andrew @ Catalyst .Net.NZ Ltd, PO Box 11-053, Manners St, Wellington
WEB: http://catalyst.net.nz/ PHYS: Level 2, 150-154 Willis St
DDI: +64(4)916-7201 MOB: +64(21)635-694 OFFICE: +64(4)499-2267
Survey for nothing with http://survey.net.nz/
---------------------------------------------------------------------