views:

355

answers:

1

At the beginning i wrote a c# class. Then i created a schema for the class with the “xsd.exe” tool. I posted this schema into the schema collection of my database and created a new xml column:

CREATE XML SCHEMA COLLECTION AppointmentSC AS 'its impossible to insert a schema here in the forum' GO

ALTER TABLE Adresse ADD xmlAppointment XML(AppointmentSC); GO

Now i can serialize/deserialize an object of my class into/out of my database. In the next step i want to save more then one object of my class into the database. I could create a collection for my class, but I also want to add new objects with sql only. I think I need an autoincrement id or a primary key or something like that. Every attempt to create a unique-id in my schema was hopeless.

I’m using Visual Studio 2008 and SQL Server 2008

best regards Raimund

A: 

I think you may have confused XML Schema for a database schema. While both have the same jobs they operate in completely different and unrelated worlds. A database has primary keys, and logically enough so should a database schema. Markup does not have primary keys and only has enumeration as meta data, and so there is no convention that you are looking for in XML Schema language.

It looks like you are trying to export a database into an XML instance that are trying to write a schema for. If that is the case then you have to accept that markup serves a completely different and unrelated function than a database table. In a database structure is implied by the meta data associated with column labels, inheritance from other tables, and so forth. In a schema for markup structure is explicitly stated using meta data that derives a descriptive structure onto bits of data/content where that meta data may or may not describe the data directly.

The problem here is not technical. You just have to practice manually writing in XML Schema language and generating instance documents from those schema to learn the differences, benefits, and weakness of markup schema versus database schema.