Re: Simple Example, How To Model It In RM

From: Neo <neo55592_at_hotmail.com>
Date: 30 Jun 2005 09:40:14 -0700
Message-ID: <1120149614.077238.3800_at_o13g2000cwo.googlegroups.com>


> what would the X[r]db script look like for a simple, > typical relational schema like this?

> create table department
> ( deptno integer primary key check (deptno between 1 and 999)
>  , dname varchar(60) not null;

Currently xrdb does not implement any high-level contraints such as "deptNo between 1 and 999". The only constraint it implements
(automatically) is that all references between things be valid. This is
the equivalent of guaranteeing that all FKs are valid in RM.

With xrdb, the burden is upon user/application to store and code higher-level constraints. Below xrdb script encodes roughly similar to the RM script above. Note the application manages the constraint data the same as any other data. Also note that there are two defaults (for whatever reason). Department default #2 is used to create a new accounting dept. Finally there is a query against the "constraints".

// Create department type
// and make it an item of main directory.
(CREATE type inst *department & dir item it)

// Create a verb named default.
(CREATE verb inst *default)

// Create deptNo, deptNoLo and deptNoHi types.
(CREATE type inst *deptNo)
(CREATE type inst *deptNoLo)
(CREATE type inst *deptNoHi)

// Create a default department named defDept1 // whose deptNo can be between 1 and 999
(CREATE department default *defDept1)
(CREATE defDept1 deptNoLo +1)
(CREATE defDept1 deptNoHi +999)

// Create a second default department named defDept2 // whose deptNo can be between 2000 and 5000.
(CREATE department default *defDept2)
(CREATE defDept2 deptNoLo +2000)
(CREATE defDept2 deptNoHi +5000)

// Create an accounting dept
// with deptNo same as deptDef2's deptNoLo.
(CREATE department inst *accounting

      & it deptNo (SELECT defDept2 deptNoLo *))

// Find the deptNoHi's for all department defaults. // Finds 999 and 5000.
(SELECT (department default *) deptNoHi *)

Constraints consists of data and code (RM shouldn't be involved too much in coding). In RM, the constraint data is stored such that it is outside of RM and the code is built into the database. In xrdb, the constraint data should/can be stored same as any other data and it is upto to the user/application to code against it. And there are no NULLs in xrdb. Received on Thu Jun 30 2005 - 18:40:14 CEST

Original text of this message