Freigeben über


sql:limit-field and sql:limit-value (SQLXML 4.0)

XML-Massenladevorgang verarbeitet die sql:limit-field Und sql:limit-value Anmerkungen pro Definition. Weitere Informationen finden Sie unter Filtern von Werten mithilfe von sql:limit-field und sql:limit-value (SQLXML 4.0).For more information, see Filtering Values Using sql:limit-field and sql:limit-value (SQLXML 4.0).

Angenommen, eine Datenbank enthält die folgenden Tabellen:

  • Kunde (CustomerID, CompanyName)

  • Adressen (CustomerID, StreetAddress, AddressType)

Ein Kunde kann viele Adressen haben, und jede Adresse hat einen Adresstyp zugeordnet (z. B. eine Lieferadresse oder eine Rechnungsadresse).

Betrachten Sie nun diese XML-Ansicht dieser Tabellen, wie im folgenden kommentierten XSD-Schema angegeben:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"  
            xmlns:sql="urn:schemas-microsoft-com:mapping-schema">  
<xsd:annotation>  
  <xsd:appinfo>  
    <sql:relationship name="CustAddr"  
        parent="Customer"  
        parent-key="CustomerID"  
        child="Address"  
        child-key="CustomerID" />  
  </xsd:appinfo>  
</xsd:annotation>  
  
  <xsd:element name="Customer" sql:relation="Customer" >  
   <xsd:complexType>  
        <xsd:attribute name="CustomerID"   type="xsd:int" />   
        <xsd:attribute name="CompanyName"  type="xsd:string" />  
        <xsd:attribute name="BillTo"   
                       type="xsd:string"   
                       sql:relation="Address"   
                       sql:field="StreetAddress"  
                       sql:limit-field="AddressType"  
                       sql:limit-value="billing"  
                       sql:relationship="CustAddr" >  
        </xsd:attribute>  
        <xsd:attribute name="ShipTo"   
                       type="xsd:string"   
                       sql:relation="Address"   
                       sql:field="StreetAddress"  
                       sql:limit-field="AddressType"  
                       sql:limit-value="shipping"  
                       sql:relationship="CustAddr" >  
        </xsd:attribute>  
    </xsd:complexType>  
  </xsd:element>  
</xsd:schema>  

Beim Empfangen dieses Schemas und dieser XML-Daten fügt XML Bulk Load den Wert ein, der für das BillTo-Attribut angegeben ist, in die StreetAddress-Spalte der CustAddress-Tabelle zusammen mit dem Wert "abrechnung" für die AddressType-Spalte ein.

Ebenso fügt XML Bulk Load den Wert ein, der für das ShipTo-Attribut angegeben ist, zusammen mit dem Wert "Versand" in der AddressType-Spalte in die Spalte "StreetAddress".

So testen Sie ein Arbeitsbeispiel

  1. Speichern Sie das schema, das in diesem Beispiel bereitgestellt wird, als SampleSchema.xml.

  2. Erstellen Sie diese Tabellen:

    CREATE TABLE Customer(  
                     CustomerID     int         PRIMARY KEY,  
                     CompanyName    varchar(20) NOT NULL)  
    GO  
    CREATE TABLE Address(  
                      CustomerID     int        FOREIGN KEY REFERENCES   
                                                 Customer(CustomerID),   
                      StreetAddress  varchar(50),  
                      AddressType    varchar(10))  
    GO  
    
  3. Speichern Sie die folgenden Beispieldaten als SampleXMLData.xml:

    <Customer CustomerID="1111" CompanyName="Sean Chai" City="NY"   
                 BillTo="111 Maple (Billing) "   
                 ShipTo="111 Maple (Shipping)" />  
    <Customer CustomerID="1112" CompanyName="Dont Know" City="LA"   
                 BillTo="222 Spruce (Billing)"   
                 ShipTo="222 Spruce (Shipping)" />  
    
  4. Zum Ausführen des XML-Massenladevorgangs speichern und ausführen Sie dieses Beispiel für Microsoft Visual Basic Scripting Edition (VBScript) als Sample.vbs:

    set objBL = CreateObject("SQLXMLBulkLoad.SQLXMLBulkload.4.0")  
    objBL.ConnectionString = "provider=SQLOLEDB;data source=localhost;database=tempdb;integrated security=SSPI"  
    objBL.ErrorLogFile = "c:\error.log"  
    objBL.XMLFragment = True  
    objBL.CheckConstraints=True  
    objBL.Execute "c:\SampleSchema.xml", "c:\SampleXMLData.xml"  
    set objBL=Nothing  
    

Dies ist das entsprechende XDR-Schema:

<?xml version="1.0" ?>  
<Schema xmlns="urn:schemas-microsoft-com:xml-data"  
        xmlns:dt="urn:schemas-microsoft-com:datatypes"  
        xmlns:sql="urn:schemas-microsoft-com:xml-sql">  
  
<ElementType name="Customer" sql:relation="Customer" >  
    <AttributeType name="CustomerID" />  
    <AttributeType name="CompanyName" />  
    <AttributeType name="BillTo" />  
    <AttributeType name="ShipTo" />  
  
    <attribute type="CustomerID" />  
    <attribute type="CompanyName" />  
    <attribute type="BillTo"   
                sql:limit-field="AddressType"  
                sql:limit-value="billing"  
                sql:field="StreetAddress"  
                sql:relation="Address" >  
                <sql:relationship   
                        key="CustomerID"  
                        key-relation="Customer"  
                        foreign-relation="Address"  
                        foreign-key="CustomerID" />  
    </attribute>  
    <attribute type="ShipTo"   
                sql:limit-field="AddressType"  
                sql:limit-value="shipping"  
                sql:field="StreetAddress"  
                sql:relation="Address" >  
                <sql:relationship   
                     key="CustomerID"  
                     key-relation="Customer"  
                     foreign-relation="Address"  
                     foreign-key="CustomerID" />  
    </attribute>  
</ElementType>  
</Schema>