开发者

DTD syntax for SQL UNIQUE constraint

开发者_高级运维

I am moving from accessing data via a database to XML for my application specific needs. I am currently writing a DTD for the XML by referring to my SQL table schema. I have defined a constraint on 4 columns to be unique(These 4 columns defines a directory structure 3 step deep so together they have to be unique eg. dir1/dir2/dir3/dirA and dir1/dir2/dir3/dirB). I know I can use an ID to maintain uniqueness of an attribute, but how can I bind this for 4 attributes together?

Thanks,

Shripad


Use an ID along with an IDREF to define this relationship. Here are two formats:

DTD

  <!DOCTYPE lab_group [
  <!ELEMENT lab_group (student_name)*>
  <!ELEMENT student_name (#PCDATA)>
  <!ATTLIST student_name student_no ID #REQUIRED>
  <!ATTLIST student_name tutor_1 IDREF #IMPLIED>
  <!ATTLIST student_name tutor_2 IDREF #IMPLIED>
  <!ATTLIST student_name tutor_3 IDREF #IMPLIED>
  <!ATTLIST student_name tutor_4 IDREF #IMPLIED>
  ]>

XSD

  <xs:element name="student_name">
   <xs:key name="ID">
     <xs:selector xpath="student_no"/>
     <xs:field xpath="@id"/>
   </xs:key>
   <xs:keyref name="IDREF" refer="ID">
     <xs:selector xpath="//student_name/@tutor_1|//student_name/@tutor_2|//student_name/@tutor_3|//student_name/@tutor_4"/>
     <xs:field xpath="@ref"/>
   </xs:keyref>
  </xs:element>

Here are a few analogues for quick reference:

  • ID => primary key
  • IDREF => foreign key
  • IDREFS => joins
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜