Thread: Relationships

Relationships

From
"Mike Hammonds"
Date:
** Reply Requested When Convenient **

How do I create relationships in PgSQL or in PgAdmin?

Mike Hammonds, CNE5, MCP-NT
Fellon-McCord & Associates, Inc.
Office:  502.214-6324
Fax:      502.426.8800
mhammonds@knowledgeinenergy.com
Show Me the Code!!
ICQ#94969305


Attachment

Re: Relationships

From
Joel Burton
Date:
> How do I create relationships in PgSQL or in PgAdmin?

Same way in most SQL-based databases: through the DDL statements such as
CREATE TABLE or ALTER TABLE.

For example

CREATE TABLE PARENT (ID INT PRIMARY KEY, LNAME TEXT);
CREATE TABLE CHILD  (PID INT REFERENCES PARENT, LNAME TEXT);

will "create a relationship" between the parent and child tables.
(If you're coming from a background in Access or something similar,
this creates a relationship
with "referential integrity" but without any cascades--PG supports
cascading; see CREATE TABLE man for details)

--
Joel Burton   <jburton@scw.org>
Director of Information Systems, Support Center of Washington