Re: Sub-Entities

From: Neo <neo55592_at_hotmail.com>
Date: 2 Jul 2005 13:25:48 -0700
Message-ID: <1120335948.502251.175730_at_f14g2000cwb.googlegroups.com>


> When creating sub-entities should you put a column in the root
> table saying what kind of sub-entity it is, or is the presence
> of a row in the more specific table?

It is more common for the more specific tables to have FKs to the root table PKs. Below example models various relationships between persons, companies, and organizations using xrdb. PKs/FKs are handled automatically by the db. Sample query at end.

// Create 4 persons.
(CREATE type inst *person & dir item it)
(CREATE person inst *john)
(CREATE person inst *mary)
(CREATE person inst *bob)
(CREATE person inst *sue)

// Create 2 companies)
(CREATE type inst *company & dir item it)
(CREATE company inst *intel)
(CREATE company inst *oracle)

// Create 3 organizations.
(CREATE type inst *organization & dir item it)
(CREATE organization inst *"boy scouts")
(CREATE organization inst *"girl scouts")
(CREATE organization inst *"cub scouts")

// Create verbs to relate person, companies and organizations.
(CREATE verb inst *client)
(CREATE verb inst *vendor)
(CREATE verb inst *employee)
(CREATE verb inst *employer)
(CREATE verb inst *sponsor)
(CREATE verb inst *competitor)
(CREATE verb inst *partner)
(CREATE verb inst *member)

// Create employee/employer relationship between intel and john.
(CREATE intel employee john)
(CREATE john employer intel)

// Create employee/employer relationship between oracle and mary.
(CREATE oracle employee mary)
(CREATE mary employer oracle)

// Create employee/employer relationships between intel/oracle and bob.
(CREATE oracle employee bob)
(CREATE bob employer oracle)
(CREATE intel employee bob)
(CREATE bob employer intel)

// Create client/vendor relationship beween intel and oracle.
(CREATE intel client oracle)
(CREATE oracle vendor intel)

// Create boy scouts are sponsored by intel.
(CREATE "boy scouts" sponsor intel)

// Create girl scouts are sponsored by oracle.
(CREATE "girl scouts" sponsor oracle)

// Create boys compete with girls and vise versa.
(CREATE "boy scouts" competitor "girl scouts")
(CREATE "girl scouts" competitor "boy scouts")

// Create partner relationship between cub scouts and boy scouts.
(CREATE "boy scouts" partner "cub scouts")
(CREATE "cub scouts" partner "boy scouts")

// Create sue is member of girl scouts.
(CREATE "girl scouts" member sue)

// Create sue is 10 yr old
(CREATE type inst *age)
(CREATE sue age +"10 yr")

// Create sue is child of john and mary, etc.
(CREATE john child sue)
(CREATE sue parent john)
(CREATE mary child sue)
(CREATE sue parent mary)

// Find a company that sponsors girl scouts
// and has an employee whose child is member of girl scouts.
// Returns oracle.

(SELECT company inst *
& "girl scouts" sponsor * & * employee (* child ("girl scouts" member *)))
Received on Sat Jul 02 2005 - 22:25:48 CEST

Original text of this message