|
[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: database primary keys in XML Schema
> 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! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|
|||||||||

Cart








