[
Lists Home |
Date Index |
Thread Index
]
Maintaining primary key / foreign key relationships and enforcing
referential integrity are slightly different things.
Primary key / foreign key relationships are usually maintained in XML
documents by nesting or by explicit references. For example, suppose I
have the following tables:
Master (MasterID, ...)
Detail (MasterID, DetailID, ...)
You can show this relationship in XML through nesting:
<Master MasterID="...">
...
<Detail DetailID="...">
...
</Detail>
<Detail DetailID="...">
...
</Detail>
</Master>
or through explicit references:
<Document>
<Master MasterID="...">
...
</Master>
...
<Detail MasterIDRef="..." DetailID="...">
...
</Detail>
...
</Document>
Note that in the first case, the MasterID is listed only once. In the
second case, it is listed for each detail record.
As to referential integrity, the nesting structure essentially enforces
it, but the reference structure does not. That is, it is perfectly legal
for a MasterIDRef attribute to have a value not listed in any MasterID
attribute. Neither structure requires MasterID or DetailID attributes to
be unique.
I suspect your instructor wants the relationships to be maintained,
rather than integrity to be enforced.
-- Ron
Marco Mastrocinque wrote:
> Hi All,
> Thanks for your help. It's for an assignment I'm doing. The lecturer
> states that I have to maintain referential integrity i.e. the Primary Key
> and Foreign Key relationships must be maintained in the resultant XML file.
|