What is the difference between using xsd:unique and xsd:key?
A:
xsd:key is unique AND is used for a collection of elements a key within a scope xsd:unique is just unique within a scope.
Hope this helps...
norbertB
2009-08-10 08:04:14
So when i declare multiple xsd:keys on different elements, all keys defined must still be unique?
Joepie
2009-08-10 08:08:01
No, If you got a collection of book elements and you declared xsd:key to be the isbn attribute of the book element in the schema. Then the values of the isbn attribute should be unique. this has no influence on other elements with other keys
norbertB
2009-08-10 09:45:24
But xsd:unique also does this. xsd:key is also scoped. I can find no differences...?
Joepie
2009-08-11 21:41:21
I think the only difference is that xsd:key is not nillable, xsd:unique is...http://www.w3.org/TR/xmlschema-0/#specifyingUniqueness
Joepie
2009-08-11 21:55:01
A:
it is similar to database.
key field is like primarykey.. unique and id
unique field is not a key but it has to be unique...
ufukgun
2009-08-10 08:06:15
A:
I found my own answer:
It all has to do with cardinality:
xsd:key is used for (0..N) and (1..1) multiplicity. xsd:unique is used for optional (0..1) multiplicity. This is also the reason why a the selected field in a xsd:unique can be nill.
Source of my answer: http://www.xml.com/lpt/a/987
Joepie
2009-08-17 15:55:36