W3C home > Mailing lists > Public > xmlschema-dev@w3.org > March 2002

Re: Problem with UNIQUE constraint

From: Gary Cramblitt <garycramblitt@comcast.net>
Date: Thu, 28 Mar 2002 20:46:03 -0500
To: xmlschema-dev@w3.org
Message-id: <3CA3810B.8019.288D5F@localhost>
On 28 Mar 2002 at 8:58, Jeni Tennison wrote:

> Hi Gary,
> 
> >> By the way, I think that you're probably using the identity constraint
> >> incorrectly. If you want to test that each Rec_SelRadioSrvc element
> >> has a unique combination of LineID and RadioService, then you need to
> >> place the identity constraint on the declaration of the element that's
> >> the *parent* of the Rec_SelRadioServc element, as follows:
> >> 
> >>   <xs:unique name="ID_SelRadioSrvc">
> >>     <xs:selector xpath="Rec_SelRadioSrvc"/>
> >>     <xs:field xpath="LineID"/>
> >>     <xs:field xpath="RadioService"/>
> >>   </xs:unique>
> >> 
> >> As you currently have it, all you're testing is that the LineID and
> >> RadioService of one Rec_SelRadioSrvc at a time. There isn't much point
> >> doing that unless you're using the identity constraint sneakily to
> >> test a co-occurrence constraint, which I don't think is the case here.
> >
> > Yes, you are quite right.  I need to change the selector xpath to "*".
> 
> Well, you can do, but that won't make any difference unless you also
> move the xs:unique identity constraint into the element declaration
> for the element that contains the elements that you want to test for
> uniqueness. If you keep the xs:unique where it is, and just change the
> selector xpath, then you'll be testing whether each child element of
> the Rec_SelRadioSrvc (i.e. the LineID and RadioService elements) have
> a unique combination of LineID and RadioService child elements, which
> I doubt is what you're after.
> 
> The location where you place the xs:unique determines the scope of the
> identity constraint. The xs:selector selects the elements that should
> be unique. The xs:field elements identify the fields on which those
> elements should be unique.

This is a database application.  The LineID and RadioService fields 
are the primary key of the Rec_SelRadioSrvc table; a multi-field 
key.  So, if I understand what you are saying I should move the 
UNIQUE constraint into the element containing Rec_SelRadioSrvc 
or into the root element (since there aren't any other tables with the 
name "Rec_SelRadioSrvc").  And leave the selector as is.  
Correct?  Thanks for your help! :-)

--
Gary Cramblitt
garycramblitt@comcast.net
Received on Thursday, 28 March 2002 20:56:38 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:30 GMT