XML  •  Create a Database Schema

Listing 4. This database schema document defines the structure of the Northwind database's Customers and Orders tables. The main mapping schema references this schema and ties it with the XML schema in Listing 3 (see Listing 5).

<?xml version="1.0" encoding="utf-8"?>
<y0:Database 
   xmlns:y0="http://schemas.microsoft.com/data/20
      02/09/28/rsd" 
   Name="Northwind">
      <y0:Schema Name="dbo">
         <y0:Tables>
            <y0:Table Name="Customers">
               <y0:Columns>
                  <y0:Column Name="CustomerID" 
                     SqlType="nchar" 
                     Length="5"/>
                  <y0:Column Name="CompanyName" 
                     SqlType="nvarchar" 
                     Length="40"/>
                  <y0:Column AllowDbNull="true" 
                     Name="ContactName" 
                     SqlType="nvarchar" 
                        Length="30"/>

            <!--Columns omitted for brevity -->

                  </y0:Columns>
                  <y0:Constraints>
                     <y0:PrimaryKey 
                        Name="PK_Customers">
                        <y0:ColumnRef 
                           Name="CustomerID"/>
                     </y0:PrimaryKey>
                  </y0:Constraints>
               </y0:Table>
            <y0:Table Name="Orders">
               <y0:Columns>
                  <y0:Column Name=
                     "OrderID" 
                     AutoIncrement=
                     "true" SqlType="int"/>
               <y0:Column Name="CustomerID" 
                  AllowDbNull="true" 
                  SqlType="nchar" Length="5"/>
               <y0:Column Name="EmployeeID" 
                  AllowDbNull="true" 
                  SqlType="int"/>

    <!--Columns omitted for brevity -->

               </y0:Columns>
               <y0:Constraints>
                  <y0:PrimaryKey 
                     Name="PK_Orders">
                     <y0:ColumnRef 
                        Name="OrderID"/>
                  </y0:PrimaryKey>
                  <y0:ForeignKey 
                     ForeignTable="Customers" 
                     Name=
                        "FK_Orders_Customers">
                     <y0:ColumnMatch 
                        ForeignName=
                        "CustomerID" 
                        Name="CustomerID"/>
                     </y0:ForeignKey>
               </y0:Constraints>
         </y0:Table>
      </y0:Tables>
   </y0:Schema>
</y0:Database>