In general, you will need to ask more details in the question ... Therefore, this should be enough to understand what else you need to determine and how. I will look at what you need to understand how to determine the primary key / foreign key by illustrating the intended student / address relationship.
First you need to determine the context in which these restrictions are stored. In my modified XSD, I call it "World."
<?xml version="1.0" encoding="utf-8" ?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="World"> <xs:complexType> <xs:sequence> <xs:element ref="Student" maxOccurs="unbounded"/> <xs:element ref="Address" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> <xs:key name="PKStudents"> <xs:selector xpath="Student/StudentID"/> <xs:field xpath="."/> </xs:key> <xs:key name="PKAddresses"> <xs:selector xpath="Address/AddressID"/> <xs:field xpath="."/> </xs:key> <xs:keyref name="FKStudentToAddress" refer="PKAddresses"> <xs:selector xpath="Student/AddressID"/> <xs:field xpath="."/> </xs:keyref> </xs:element> <xs:element name="Student"> <xs:complexType> <xs:sequence> <xs:element name="Title" type="xs:string"/> <xs:element name="FirstName" type="xs:string"/> <xs:element name="LastName" type="xs:string"/> <xs:element name="Dateborn" type="xs:date"/> <xs:element name="Gender" type="xs:string"/> <xs:element name="StudentID" type="xs:string"/> <xs:element name="AddressID" type="xs:string" minOccurs="0"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="Address"> <xs:complexType> <xs:sequence> <xs:element name="AddressID" type="xs:string"/> <xs:element name="Street" type="xs:string"/> <xs:element name="City" type="xs:string"/> <xs:element name="Province" type="xs:string" minOccurs="0"/> <xs:element name="Country" type="xs:date" minOccurs="0"/> <xs:element name="PostalCode" type="xs:string" minOccurs="0"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
Then, similar XML will fail or fail, depending on what you do with the values ββin the StudentID and AddressID fields.
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <World xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Student> <Title>Title1</Title> <FirstName>FirstName1</FirstName> <LastName>LastName1</LastName> <Dateborn>1900-01-01</Dateborn> <Gender>Gender1</Gender> <StudentID>StudentID1</StudentID> <AddressID>AddressID1</AddressID> </Student> <Student> <Title>Title1</Title> <FirstName>FirstName1</FirstName> <LastName>LastName1</LastName> <Dateborn>1900-01-01</Dateborn> <Gender>Gender1</Gender> <StudentID>StudentID2</StudentID> <AddressID>AddressID1</AddressID> </Student> <Address> <AddressID>AddressID1</AddressID> <Street>Street1</Street> <City>City1</City> <Province>Province1</Province> <Country>1900-01-01</Country> <PostalCode>PostalCode1</PostalCode> </Address> <Address> <AddressID>AddressID2</AddressID> <Street>Street1</Street> <City>City1</City> <Province>Province1</Province> <Country>1900-01-01</Country> <PostalCode>PostalCode1</PostalCode> </Address> </World>
To complete your decision, you need to define the Course and Class of "entities" in your world, define xs:key for each, similar to Student / * Address *, then add the CourseID and GradeID attributes to the entities that need them, and finally define keyref as described above for Entity before Grade and Entity - Course .
source share