적용 대상:SQL Server
Azure SQL Database
updategram은 레코드 인스턴스가 블록에 나타나지만 해당 <after> 블록에는 <before> 나타나지 않을 때 삽입 작업을 나타냅니다. 이 경우 updategram은 블록의 레코드를 <after> 데이터베이스에 삽입합니다.
삽입 작업에 대한 Updategram 형식은 다음과 같습니다.
<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
<updg:sync [mapping-schema="SampleSchema.xml"] >
[<updg:before>
</updg:before>]
<updg:after [updg:returnid="x y ..."] >
<ElementName [updg:id="value"]
[updg:at-identity="x"]
[updg:guid="y"]
attribute="value"
attribute="value"
...
/>
[<ElementName .../>... ]
</updg:after>
</updg:sync>
</ROOT>
<before> 블록
삽입 작업에 대해 <before> 블록을 생략할 수 있습니다. 선택적 mapping-schema 특성을 지정 <ElementName> 하지 않으면 updategram에 지정된 특성이 데이터베이스 테이블에 매핑되고 자식 요소 또는 특성이 테이블의 열에 매핑됩니다.
<after> 블록
블록에서 하나 이상의 레코드를 <after> 지정할 수 있습니다.
블록이 <after> 특정 열에 대한 값을 제공하지 않는 경우 updategram은 주석이 추가된 스키마에 지정된 기본값(스키마가 지정된 경우)을 사용합니다. 스키마가 열의 기본값을 지정하지 않으면 updategram은 이 열에 명시적 값을 지정하지 않고 대신 SQL Server 기본값(지정된 경우)을 이 열에 할당합니다. SQL Server 기본값이 없고 열이 값을 수락 NULL 하는 경우 updategram은 열 값을 .로 NULL설정합니다. 열에 기본값이 없거나 값을 수락 NULL 하면 명령이 실패하고 updategram이 오류를 반환합니다. 선택적 updg:returnid 특성은 -type 열이 있는 테이블에 레코드가 추가될 때 시스템에서 생성되는 ID 값을 반환하는 IDENTITY데 사용됩니다.
updg:id 속성
updategram이 레코드만 삽입하는 경우 updategram에는 특성이 updg:id 필요하지 않습니다. 자세한 updg:id내용은 XML 업데이트그램을 사용하여 데이터 업데이트(SQLXML 4.0)를 참조하세요.
updg:at-identity 속성
updategram이 -type 열이 있는 테이블에 레코드를 IDENTITY삽입하는 경우 updategram은 선택적 updg:at-identity 특성을 사용하여 시스템 할당 값을 캡처할 수 있습니다. 그런 다음 updategram은 후속 작업에서 이 값을 사용할 수 있습니다. updategram을 실행하면 특성을 지정하여 생성된 ID 값을 반환할 updg:returnid 수 있습니다.
updg:guid 속성
특성은 updg:guid 전역적으로 고유한 식별자를 생성하는 선택적 특성입니다. 이 값은 지정된 전체 <sync> 블록의 범위에 남아 있습니다. 이 값은 블록의 <sync> 아무 곳이나 사용할 수 있습니다. 이 특성은 SQL Server 함수를 NEWGUID() 호출하여 고유 식별자를 생성합니다.
예제
다음 예제를 사용하여 작업 샘플을 만들려면 SQLXML 실행 요구 사항 예제에 지정된 요구 사항을 충족해야 합니다.
updategram 예제를 사용하기 전에 다음을 고려합니다.
대부분의 예제에서는 기본 매핑을 사용합니다(즉, updategram에 매핑 스키마가 지정되지 않음). 매핑 스키마 를 사용하는 updategram에 대한 자세한 예제는 Updategram에서 주석이 추가된 매핑 스키마 지정(SQLXML 4.0)을 참조하세요.
대부분의 예제에서는 샘플 데이터베이스를
AdventureWorks2025사용합니다. 모든 업데이트는 이 데이터베이스의 테이블에 적용됩니다.
A. updategram을 사용하여 레코드 삽입
이 특성 중심 updategram은 데이터베이스의 테이블에 레코드를 HumanResources.EmployeeAdventureWorks2025 삽입합니다.
이 예제에서 updategram은 매핑 스키마를 지정하지 않습니다. 요소 이름은 테이블 이름에 매핑되고 특성 또는 자식 요소는 해당 테이블의 열에 매핑되는 기본 매핑을 사용합니다.
HumanResources.Department 테이블에 대한 AdventureWorks2025 스키마는 모든 열에 'not null' 제한을 적용합니다. 따라서 updategram은 모든 열에 대해 지정된 값을 포함해야 합니다. DepartmentID는 -type 열입니다 IDENTITY. 따라서 값은 지정되지 않습니다.
<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
<updg:sync>
<updg:before>
</updg:before>
<updg:after>
<HumanResources.Department Name="New Product Research" GroupName="Research and Development" ModifiedDate="2010-08-31" />
</updg:after>
</updg:sync>
</ROOT>
스키마에 대해 샘플 XPath 쿼리 테스트
이전 updategram을 복사하여 텍스트 파일에 붙여넣습니다. 파일을
MyUpdategram.xml로 저장합니다.SQLXML 4.0 테스트 스크립트(
Sqlxml4test.vbs)를 만들고 사용하여 템플릿을 실행합니다.자세한 내용은 ADO를 사용한 SQLXML 4.0 쿼리를 실행합니다.
요소 중심 매핑에서 updategram은 다음과 같습니다.
<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
<updg:sync>
<updg:before>
</updg:before>
<updg:after>
<HumanResources.Department>
<Name> New Product Research </Name>
<GroupName> Research and Development </GroupName>
<ModifiedDate>2010-08-31</ModifiedDate>
</HumanResources.Department>
</updg:after>
</updg:sync>
</ROOT>
혼합 모드(요소 중심 및 특성 중심) updategram에서 요소는 다음 updategram에 표시된 대로 특성과 하위 요소를 모두 가질 수 있습니다.
<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
<updg:sync>
<updg:before>
</updg:before>
<updg:after>
<HumanResources.Department Name="New Product Research">
<GroupName>Research and Development</GroupName>
<ModifiedDate>2010-08-31</ModifiedDate>
</HumanResources.Department>
</updg:after>
</updg:sync>
</ROOT>
B. updategram을 사용하여 여러 레코드 삽입
이 updategram은 테이블에 두 개의 새 교대 근무 레코드를 추가합니다 HumanResources.Shift . updategram은 선택적 <before> 블록을 지정하지 않습니다.
<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
<updg:sync>
<updg:after>
<HumanResources.Shift Name="Day-Evening" StartTime="1900-01-01 11:00:00.000" EndTime="1900-01-01 19:00:00.000" ModifiedDate="2004-01-01 00:00:00.000" />
<HumanResources.Shift Name="Evening-Night" StartTime="1900-01-01 19:00:00.000" EndTime="1900-01-01 03:00:00.000" ModifiedDate="2004-01-01 00:00:00.000" />
</updg:after>
</updg:sync>
</ROOT>
스키마에 대해 샘플 XPath 쿼리 테스트
이전 updategram을 복사하여 텍스트 파일에 붙여넣습니다. 파일을
Updategram-AddShifts.xml로 저장합니다.SQLXML 4.0 테스트 스크립트(
Sqlxml4test.vbs)를 만들고 사용하여 템플릿을 실행합니다.자세한 내용은 ADO를 사용한 SQLXML 4.0 쿼리를 실행합니다.
이 예제의 또 다른 버전은 한 블록 대신 두 개의 개별 <after> 블록을 사용하여 두 명의 직원을 삽입하는 updategram입니다. 이는 유효하며 다음과 같이 인코딩할 수 있습니다.
<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
<updg:sync>
<updg:after>
<HumanResources.Shift Name="Day-Evening" StartTime="1900-01-01 11:00:00.000" EndTime="1900-01-01 19:00:00.000" ModifiedDate="2004-01-01 00:00:00.000" />
</updg:after>
<updg:before>
</updg:before>
<updg:after>
<HumanResources.Shift Name="Evening-Night" StartTime="1900-01-01 19:00:00.000" EndTime="1900-01-01 03:00:00.000" ModifiedDate="2004-01-01 00:00:00.000" />
</updg:after>
</updg:sync>
</ROOT>
C. XML에서 유효하지 않은 유효한 SQL Server 문자 사용
SQL Server에서 테이블 이름에는 Northwind 데이터베이스의 Order Details 테이블과 같은 공백이 포함될 수 있습니다. 그러나 유효한 SQL Server 식별자이지만 유효한 XML 식별자가 아닌 XML 문자에서는 유효하지 않지만 인코딩 값으로 인 _xHHHH_ 코딩할 수 있습니다. 여기서 HHHH 가장 중요한 비트 우선 순서의 문자에 대한 4자리 16진수 UCS-2 코드를 나타냅니다.
참고 항목
이 예에서는 Northwind 데이터베이스를 사용합니다. 이 Microsoft 웹 사이트에서 다운로드할 수 있는 SQL 스크립트를 사용하여 Northwind 데이터베이스를 설치할 수 있습니다.
또한 요소 이름은 대괄호([ ])로 묶어야 합니다. XML에서는 문자 [and]가 유효하지 않으므로 각각 다른 문자로 _x005B__x005D_인코딩해야 합니다. (매핑 스키마를 사용하는 경우 공백과 같이 유효하지 않은 문자를 포함하지 않는 요소 이름을 제공할 수 있습니다. 매핑 스키마는 필요한 매핑을 수행합니다. 따라서 이러한 문자에 대해 인코딩할 필요가 없습니다.)
이 updategram은 Northwind 데이터베이스의 Order Details 테이블에 레코드를 추가합니다.
<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
<updg:sync>
<updg:before>
</updg:before>
<updg:after>
<_x005B_Order_x0020_Details_x005D_ OrderID="1" ProductID="11" UnitPrice="$1.0" Quantity="1" Discount="0.0" />
</updg:after>
</updg:sync>
</ROOT>
주문 세부 정보 테이블의 UnitPrice 열은 금액 유형입니다. 적절한 형식 변환( 문자열 형식에서 money 형식으로)을 적용하려면 값의 일부로 달러 기호($)를 추가해야 합니다. updategram이 매핑 스키마를 지정하지 않으면 문자열 값의 첫 번째 문자가 평가됩니다. 첫 번째 문자가 달러 기호($)인 경우 적절한 변환이 적용됩니다.
열이 적절하게 dt:type="fixed.14.4"sql:datatype="money"표시되거나 달러 기호($)가 필요하지 않고 매핑에 의해 변환이 처리되는 매핑 스키마에 대해 updategram을 지정하는 경우 적절한 형식 변환을 수행하려는 이 방법을 사용하는 것이 좋습니다.
스키마에 대해 샘플 XPath 쿼리 테스트
이전 updategram을 복사하여 텍스트 파일에 붙여넣습니다. 파일을
UpdategramSpacesInTableName.xml로 저장합니다.SQLXML 4.0 테스트 스크립트(
Sqlxml4test.vbs)를 만들고 사용하여 템플릿을 실행합니다.자세한 내용은 ADO를 사용한 SQLXML 4.0 쿼리를 실행합니다.
D. ID 기반 특성을 사용하여 IDENTITY 형식 열에 삽입된 값을 검색합니다.
다음 updategram은 두 개의 레코드를 삽입합니다. 하나는 테이블에, 다른 Sales.SalesOrderHeader 하나는 Sales.SalesOrderDetail 테이블에 삽입됩니다.
먼저 updategram은 테이블에 레코드를 추가합니다 Sales.SalesOrderHeader . 이 표에서 SalesOrderID 열은 -type 열입니다 IDENTITY. 따라서 이 레코드를 테이블에 추가하면 updategram은 특성을 사용하여 at-identity 할당된 SalesOrderID 값을 "x"(자리 표시자 값)로 캡처합니다. 그런 다음 Updategram은 이 at-identity 변수를 Sales.SalesOrderDetail< 요소의 SalesOrderID 특성 >값으로 지정합니다.
<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
<updg:sync>
<updg:before>
</updg:before>
<updg:after>
<Sales.SalesOrderHeader updg:at-identity="x" RevisionNumber="1" OrderDate="2001-07-01 00:00:00.000" DueDate="2001-07-13 00:00:00.000" OnlineOrderFlag="0" CustomerID="676" ContactID="378" BillToAddressID="985" ShipToAddressID="985" ShipMethodID="5" SubTotal="24643.9362" TaxAmt="1971.5149" Freight="616.0984" rowguid="00001111-2222-3333-4444-556677889900" ModifiedDate="2001-07-08 00:00:00.000" />
<Sales.SalesOrderDetail SalesOrderID="x" LineNumber="1" OrderQty="1" ProductID="776" SpecialOfferID="1" UnitPrice="2429.9928" UnitPriceDiscount="0.00" rowguid="aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" ModifiedDate="2001-07-01 00:00:00.000" />
</updg:after>
</updg:sync>
</ROOT>
특성에 의해 updg:at-identity 생성된 ID 값을 반환하려는 경우 특성을 사용할 updg:returnid 수 있습니다. 다음 예제는 이 ID 값을 반환하는 수정된 updategram입니다. (이 updategram은 예제를 좀 더 복잡하게 만들기 위해 두 개의 주문 레코드와 두 개의 주문 세부 정보 레코드를 추가합니다.)
<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
<updg:sync>
<updg:before>
</updg:before>
<updg:after updg:returnid="x y">
<HumanResources.Shift updg:at-identity="x" Name="Day-Evening" StartTime="1900-01-01 11:00:00.000" EndTime="1900-01-01 19:00:00.000" ModifiedDate="2004-01-01 00:00:00.000" />
<HumanResources.Shift updg:at-identity="y" Name="Evening-Night" StartTime="1900-01-01 19:00:00.000" EndTime="1900-01-01 03:00:00.000" ModifiedDate="2004-01-01 00:00:00.000" />
</updg:after>
</updg:sync>
</ROOT>
updategram이 실행되면 생성된 ID 값(테이블 ID에 사용되는 ShiftID 열의 생성된 값)을 포함하는 다음 예제와 유사한 결과가 반환됩니다.
<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
<returnid>
<x>4</x>
<y>5</y>
</returnid>
</ROOT>
스키마에 대해 샘플 XPath 쿼리 테스트
이전 updategram을 복사하여 텍스트 파일에 붙여넣습니다. 파일을
Updategram-returnId.xml로 저장합니다.SQLXML 4.0 테스트 스크립트(
Sqlxml4test.vbs)를 만들고 사용하여 템플릿을 실행합니다.자세한 내용은 ADO를 사용한 SQLXML 4.0 쿼리를 실행합니다.
E.
updg:guid 특성을 사용하여 고유 값 생성
이 예제에서 updategram은 Cust 및 CustOrder 테이블에 레코드를 삽입합니다. 또한 updategram은 특성을 사용하여 updg:guid CustomerID 특성에 대한 고유 값을 생성합니다.
<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
<updg:sync>
<updg:before>
</updg:before>
<updg:after updg:returnid="x">
<Cust updg:guid="x">
<CustID>x</CustID>
<LastName>Fuller</LastName>
</Cust>
<CustOrder>
<CustID>x</CustID>
<OrderID>1</OrderID>
</CustOrder>
</updg:after>
</updg:sync>
</ROOT>
updategram은 특성을 지정합니다 returnid . 결과적으로 생성된 GUID가 반환됩니다.
<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
<returnid>
<x>7111BD1A-7F0B-4CEE-B411-260DADFEFA2A</x>
</returnid>
</ROOT>
updategram 테스트
이전 updategram을 복사하여 텍스트 파일에 붙여넣습니다. 파일을
Updategram-GenerateGuid.xml로 저장합니다.다음 테이블을 만듭니다.
USE tempdb; CREATE TABLE Cust ( CustID UNIQUEIDENTIFIER, LastName VARCHAR (20) ); CREATE TABLE CustOrder ( CustID UNIQUEIDENTIFIER, OrderID INT );SQLXML 4.0 테스트 스크립트(
Sqlxml4test.vbs)를 만들고 사용하여 템플릿을 실행합니다.자세한 내용은 ADO를 사용한 SQLXML 4.0 쿼리를 실행합니다.
F. updategram에서 스키마 지정
이 예제의 updategram은 다음 표에 레코드를 삽입합니다.
CustOrder(OrderID, EmployeeID, OrderType)
XSD 스키마는 이 updategram에 지정됩니다(즉, updategram 요소 및 특성의 기본 매핑은 없음). 스키마는 요소와 특성을 데이터베이스 테이블 및 열에 매핑하는 데 필요한 기능을 제공합니다.
다음 스키마(CustOrderSchema.xml)는 특성과 <CustOrder> 특성으로 구성된 요소를 설명 OrderID 합니다EmployeeID. 스키마를 더 흥미롭게 만들기 위해 기본값이 특성에 EmployeeID 할당됩니다. updategram은 삽입 작업에만 특성의 기본값을 사용하고 updategram이 해당 특성을 지정하지 않는 경우에만 사용합니다.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<xsd:element name="CustOrder">
<xsd:complexType>
<xsd:attribute name="OrderID" type="xsd:integer" />
<xsd:attribute name="EmployeeID" type="xsd:integer" />
<xsd:attribute name="OrderType " type="xsd:integer" default="1" />
</xsd:complexType>
</xsd:element>
</xsd:schema>
이 updategram은 CustOrder 테이블에 레코드를 삽입합니다. updategram은 OrderID 및 EmployeeID 특성 값만 지정합니다. OrderType 특성 값은 지정하지 않습니다. 따라서 Updategram은 앞의 스키마에 지정된 EmployeeID 특성의 기본값을 사용합니다.
<ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql" xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
<updg:sync mapping-schema="CustOrderSchema.xml">
<updg:after>
<CustOrder OrderID="98000" EmployeeID="1" />
</updg:after>
</updg:sync>
</ROOT>
매핑 스키마 를 지정하는 updategram에 대한 자세한 예제는 Updategram에서 주석이 추가된 매핑 스키마 지정(SQLXML 4.0)을 참조하세요.
updategram 테스트
데이터베이스에서
tempdb다음 테이블을 만듭니다.USE tempdb; CREATE TABLE CustOrder ( OrderID INT, EmployeeID INT, OrderType INT );이전 스키마를 복사하여 텍스트 파일에 붙여넣습니다. 파일을
CustOrderSchema.xml로 저장합니다.이전 updategram을 복사하여 텍스트 파일에 붙여넣습니다. 이전 단계에서 사용한 것과
CustOrderUpdategram.xml동일한 폴더에 파일을 저장합니다.SQLXML 4.0 테스트 스크립트(
Sqlxml4test.vbs)를 만들고 사용하여 updategram을 실행합니다.자세한 내용은 ADO를 사용한 SQLXML 4.0 쿼리를 실행합니다.
해당하는 XDR 스키마입니다.
<Schema xmlns="urn:schemas-microsoft-com:xml-data" xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<ElementType name="CustOrder">
<AttributeType name="OrderID" />
<AttributeType name="EmployeeID" />
<AttributeType name="OrderType" default="1" />
<attribute type="OrderID" />
<attribute type="EmployeeID" />
<attribute type="OrderType" />
</ElementType>
</Schema>
G. xsi:nil 특성을 사용하여 열에 null 값 삽입
테이블의 해당 열에 null 값을 삽입하려는 경우 updategram의 xsi:nil 요소에 특성을 지정할 수 있습니다. 해당 XSD 스키마에서 XSD nillable 특성도 지정해야 합니다.
예를 들어 다음 XSD 스키마를 고려합니다.
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<xsd:element name="Student" sql:relation="Students">
<xsd:complexType>
<xsd:all>
<xsd:element name="fname" sql:field="first_name" type="xsd:string" nillable="true" />
</xsd:all>
<xsd:attribute name="SID" sql:field="StudentID" type="xsd:ID" />
<xsd:attribute name="lname" sql:field="last_name" type="xsd:string" />
<xsd:attribute name="minitial" sql:field="middle_initial" type="xsd:string" />
<xsd:attribute name="years" sql:field="no_of_years" type="xsd:integer" />
</xsd:complexType>
</xsd:element>
</xsd:schema>
XSD 스키마는 요소에 nillable="true" 대해 지정합니다<fname>. 다음 updategram은 이 스키마를 사용합니다.
<ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql" xmlns:updg="urn:schemas-microsoft-com:xml-updategram" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<updg:sync mapping-schema="StudentSchema.xml">
<updg:before />
<updg:after>
<Student SID="S00004" lname="Elmaci" minitial="" years="2">
<fname xsi:nil="true">
</fname>
</Student>
</updg:after>
</updg:sync>
</ROOT>
updategram은 블록의 xsi:nil 요소에 <fname> 대해 지정합니다<after>. 따라서 이 updategram이 실행되면 테이블의 NULL first_name 열에 대한 값이 삽입됩니다.
updategram 테스트
데이터베이스에서
tempdb다음 테이블을 만듭니다.USE tempdb; CREATE TABLE Students ( StudentID CHAR (6) NOT NULL, first_name VARCHAR (50), last_name VARCHAR (50), middle_initial CHAR (1), no_of_years INT NULL ); GO이전 스키마를 복사하여 텍스트 파일에 붙여넣습니다. 파일을
StudentSchema.xml로 저장합니다.이전 updategram을 복사하여 텍스트 파일에 붙여넣습니다. 파일을 저장하기
StudentUpdategram.xml위해 이전 단계에서 사용한 것과 동일한 폴더에 저장StudentSchema.xml합니다.SQLXML 4.0 테스트 스크립트(
Sqlxml4test.vbs)를 만들고 사용하여 updategram을 실행합니다.자세한 내용은 ADO를 사용한 SQLXML 4.0 쿼리를 실행합니다.
H. updategram에서 네임스페이스 지정
updategram에서 updategram의 동일한 요소에 선언된 네임스페이스에 속하는 요소를 포함할 수 있습니다. 이 경우 해당 스키마도 동일한 네임스페이스를 선언해야 하며 요소는 해당 대상 네임스페이스에 속해야 합니다.
예를 들어 다음 updategram(UpdateGram-ElementHavingNamespace.xml) <Order> 에서 요소는 요소에 선언된 네임스페이스에 속합니다.
<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
<updg:sync mapping-schema="XSD-ElementHavingNameSpace.xml">
<updg:after>
<x:Order xmlns:x="https://server/xyz/schemas/" updg:at-identity="SalesOrderID" RevisionNumber="1" OrderDate="2001-07-01 00:00:00.000" DueDate="2001-07-13 00:00:00.000" OnlineOrderFlag="0" CustomerID="676" ContactID="378" BillToAddressID="985" ShipToAddressID="985" ShipMethodID="5" SubTotal="24643.9362" TaxAmt="1971.5149" Freight="616.0984" rowguid="00009999-8888-7777-6666-554433221100" ModifiedDate="2001-07-08 00:00:00.000" />
</updg:after>
</updg:sync>
</ROOT>
이 경우 스키마에서도 이 스키마와 같이 해당 네임스페이스를 선언해야 합니다.
다음 스키마(XSD-ElementHavingNamespace.xml)는 해당 요소와 특성을 선언하는 방법을 보여 줍니다.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:dt="urn:schemas-microsoft-com:datatypes" xmlns:sql="urn:schemas-microsoft-com:mapping-schema" xmlns:x="https://server/xyz/schemas/" targetNamespace="https://server/xyz/schemas/">
<xsd:element name="Order" sql:relation="Sales.SalesOrderHeader" type="x:Order_type" />
<xsd:complexType name="Order_type">
<xsd:attribute name="SalesOrderID" type="xsd:ID" />
<xsd:attribute name="RevisionNumber" type="xsd:unsignedByte" />
<xsd:attribute name="OrderDate" type="xsd:dateTime" />
<xsd:attribute name="DueDate" type="xsd:dateTime" />
<xsd:attribute name="ShipDate" type="xsd:dateTime" />
<xsd:attribute name="Status" type="xsd:unsignedByte" />
<xsd:attribute name="OnlineOrderFlag" type="xsd:boolean" />
<xsd:attribute name="SalesOrderNumber" type="xsd:string" />
<xsd:attribute name="PurchaseOrderNumber" type="xsd:string" />
<xsd:attribute name="AccountNumber" type="xsd:string" />
<xsd:attribute name="CustomerID" type="xsd:int" />
<xsd:attribute name="ContactID" type="xsd:int" />
<xsd:attribute name="SalesPersonID" type="xsd:int" />
<xsd:attribute name="TerritoryID" type="xsd:int" />
<xsd:attribute name="BillToAddressID" type="xsd:int" />
<xsd:attribute name="ShipToAddressID" type="xsd:int" />
<xsd:attribute name="ShipMethodID" type="xsd:int" />
<xsd:attribute name="CreditCardID" type="xsd:int" />
<xsd:attribute name="CreditCardApprovalCode" type="xsd:string" />
<xsd:attribute name="CurrencyRateID" type="xsd:int" />
<xsd:attribute name="SubTotal" type="xsd:decimal" />
<xsd:attribute name="TaxAmt" type="xsd:decimal" />
<xsd:attribute name="Freight" type="xsd:decimal" />
<xsd:attribute name="TotalDue" type="xsd:decimal" />
<xsd:attribute name="Comment" type="xsd:string" />
<xsd:attribute name="rowguid" type="xsd:string" />
<xsd:attribute name="ModifiedDate" type="xsd:dateTime" />
</xsd:complexType>
</xsd:schema>
updategram 테스트
이전 스키마를 복사하여 텍스트 파일에 붙여넣습니다. 파일을
XSD-ElementHavingNamespace.xml로 저장합니다.이전 updategram을 복사하여 텍스트 파일에 붙여넣습니다.
Updategram-ElementHavingNamespace.xml파일을 저장하는 데 사용된 것과 동일한 폴더에 저장XSD-ElementHavingnamespace.xml합니다.SQLXML 4.0 테스트 스크립트(
Sqlxml4test.vbs)를 만들고 사용하여 updategram을 실행합니다.자세한 내용은 ADO를 사용한 SQLXML 4.0 쿼리를 실행합니다.
9\. XML 데이터 형식 열에 데이터 삽입
updategram을 사용하여 다음과 같은 사항을 고려하여 xml 데이터 형식 열에 저장된 데이터를 삽입하고 업데이트할 수 있습니다.
xml 열은 기존 행을 식별하는 데 사용할 수 없습니다. 따라서 updategram의 섹션에
updg:before포함할 수 없습니다.xml 열에 삽입된 XML 조각의 범위에 있는 네임스페이스는 유지되고 네임스페이스 선언은 삽입된 조각의 맨 위 요소에 추가됩니다.
예를 들어 다음 updategram(SampleUpdateGram.xml) <Desc> 에서 요소는 샘플 데이터베이스의 Production>productModel 테이블에 AdventureWorks2025 있는 ProductDescription 열을 업데이트합니다. 이 updategram의 결과는 ProductDescription 열의 XML 콘텐츠가 요소의 XML 내용으로 업데이트된다는 것입니다 <Desc> .
<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
<updg:sync mapping-schema="SampleSchema.xml">
<updg:before>
<ProductModel ProductModelID="19">
<Name>Mountain-100</Name>
</ProductModel>
</updg:before>
<updg:after>
<ProductModel>
<Name>Mountain-100</Name>
<Desc>
<?xml href="ProductDescription.xsl" type="text/xsl" e="text/xsl"?>
<p1:ProductDescription xmlns:p1="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription" xmlns:wm="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelWarrAndMain" xmlns:wf="https://www.adventure-works.com/schemas/OtherFeatures" xmlns:html="http://www.w3.org/1999/xhtml" xmlns="">
<p1:Summary>
<html:p>Insert Example</html:p>
</p1:Summary>
<p1:Manufacturer>
<p1:Name>AdventureWorks</p1:Name>
<p1:Copyright>2002</p1:Copyright>
<p1:ProductURL>HTTP://www.Adventure-works.com</p1:ProductURL>
</p1:Manufacturer>
<p1:Features>
These are the product highlights.
<wm:Warranty>
<wm:WarrantyPeriod>3 years</wm:WarrantyPeriod>
<wm:Description>parts and labor</wm:Description>
</wm:Warranty>
<wm:Maintenance>
<wm:NoOfYears>10 years</wm:NoOfYears>
<wm:Description>maintenance contract available through your dealer or any AdventureWorks retail store.</wm:Description>
</wm:Maintenance>
<wf:wheel>High performance wheels.</wf:wheel>
<wf:saddle>
<html:i>Anatomic design</html:i>
and made from durable leather for a full-day of riding in comfort.
</wf:saddle>
<wf:pedal>
<html:b>Top-of-the-line</html:b>
clipless pedals with adjustable tension.
</wf:pedal>
<wf:BikeFrame>Each frame is hand-crafted in our Bothell facility to the optimum diameter and wall-thickness required of a premium mountain frame. The heat-treated welded aluminum frame has a larger diameter tube that absorbs the bumps.</wf:BikeFrame>
<wf:crankset> Triple crankset; aluminum crank arm; flawless shifting. </wf:crankset>
</p1:Features>
<p1:Picture>
<p1:Angle>front</p1:Angle>
<p1:Size>small</p1:Size>
<p1:ProductPhotoID>118</p1:ProductPhotoID>
</p1:Picture>
<p1:Specifications>
These are the product specifications.
<Material>Aluminum Alloy</Material>
<Color>Available in most colors</Color>
<ProductLine>Mountain bike</ProductLine>
<Style>Unisex</Style>
<RiderExperience>Advanced to Professional riders</RiderExperience>
</p1:Specifications>
</p1:ProductDescription>
</Desc>
</ProductModel>
</updg:after>
</updg:sync>
</ROOT>
updategram은 다음과 같은 주석이 추가된 XSD 스키마(SampleSchema.xml)를 참조합니다.
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sql="urn:schemas-microsoft-com:mapping-schema" xmlns="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription">
<xsd:element name="ProductModel" sql:relation="Production.ProductModel">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Name" type="xsd:string"></xsd:element>
<xsd:element name="Desc" sql:field="CatalogDescription" sql:datatype="xml">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ProductDescription">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Summary" type="xsd:anyType">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="ProductModelID" sql:field="ProductModelID" />
</xsd:complexType>
</xsd:element>
</xsd:schema>
updategram 테스트
이전 스키마를 복사하여 텍스트 파일에 붙여넣습니다. 파일을
XSD-SampleSchema.xml로 저장합니다.참고 항목
updategrams는 기본 매핑을 지원하므로 xml 데이터 형식의 시작과 끝을 식별할 방법이 없습니다. 이는 xml 데이터 형식 열을 사용하여 테이블을 삽입하거나 업데이트할 때 매핑 스키마가 필요하다는 것을 의미합니다. 스키마가 제공되지 않으면 SQLXML은 테이블에서 열 중 하나가 누락되었음을 나타내는 오류를 반환합니다.
이전 updategram을 복사하여 텍스트 파일에 붙여넣습니다.
SampleUpdategram.xml파일을 저장하는 데 사용된 것과 동일한 폴더에 저장SampleSchema.xml합니다.SQLXML 4.0 테스트 스크립트(
Sqlxml4test.vbs)를 만들고 사용하여 updategram을 실행합니다.자세한 내용은 ADO를 사용한 SQLXML 4.0 쿼리를 실행합니다.