OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] database primary keys in XML Schema

[ Lists Home | Date Index | Thread Index ]

> 1.) When I insert data via XML instance documents the first time, I cannot
> specify a primary key in my XML instance document because the database
> automatically creates an auto-increment key. Correct?

You might use a dummy key just for the xml instance (not going into the
database), to keep track of the record. Though you may not need it.

You may also (if you control the database) use a GUID as the primary key.
That way you can set the key before inserting it, because it is sure to be
unique.

> 2.) What if I, for example, want to insert a city in a geography database
> (the database has a Country and a City table; 1:n relationship). When
inserting
> a city, how can I specify to which country the city belongs? I needed to
> know the database primary key for the country, wouldn't I and add this key
as an
> attribute to the city in my instance document?
> What other solutions do exist?

You could nest the city beneath the country, but that doesn't work well if
you have a table which is a link between two tables.

Other than that, I still suggest using within-the-xml-instance dummy keys.
Think of your xml instance not as a mirror of the data in the database, but
as something that handles the data in the database. And, within the xml
instance, use a global counter for the keys, so you don't have to keep track
of which keys are going into which tables. Again, this is xml instance
housekeeping, not the database. (The dummy keys could be xml IDs.)

I'd better stop talking now...

-tor





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS