[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: database primary keys in XML Schema


xml primary key
> 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


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.