Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 SQL 2005 XML Schemas - Defining a Unique Attribute

Author  Topic 

Sheki
Starting Member

2 Posts

Posted - 2009-05-20 : 15:01:58
Here's a Sample xml document I'm trying to create a schema for:

'<Fields>
<Field ID="-1">somevalue</Field>
<Field ID="-2" />
<Field ID="-3" />
<Field ID="-4">Some other value</Field>
<Field ID="-5" /></Fields>'

I'm trying to create a SQL Server 2005 schema collection to:
1. prevent dupicate id's.
2. only allow negative ids.

I can achieve the negative constraint with type="xs:negativeInteger" for the id attribute. But I can't create a unique constraint or key\keyref in SQL 2005. If I set my type="xs:ID", then I cant use numbers at all for my ID values, nevermind negative IDs.

Either I'm missing something, or its not possible. If its not possible, why would SQL 2005 not support the ability to have a unique attribute? Is there a work around using a constraint\trigger or an xml index on the table, or some other technique that I cant even imagine right now?

All help is greatly appreciated.
   

- Advertisement -