, 우리는 몇 가지 설명을해야 할 수도 있습니다. 어쩌면 문제를 다시 말하면 다음과 같이 묻습니다.
내장 xml 유형에 의존하지 않고 기존 xml을 SQL 2005 데이터베이스로 가져올 수있는 방법은 무엇입니까? 이미 언급 한
상당히 똑바로 앞으로 솔루션은 OPENXML과 결합 를 sp_xml_preparedocument이다.
다음 예제는 올바른 사용법을 보여줍니다. 더 완벽한 예제 체크 아웃은 MSDN 문서 Using OPENXML에 있습니다.
declare @XmlDocumentHandle int
declare @XmlDocument nvarchar(1000)
set @XmlDocument = N'<ROOT>
<Customer>
<FirstName>Will</FirstName>
<LastName>Smith</LastName>
</Customer>
</ROOT>'
-- Create temp table to insert data into
create table #Customer
(
FirstName varchar(20),
LastName varchar(20)
)
-- Create an internal representation of the XML document.
exec sp_xml_preparedocument @XmlDocumentHandle output, @XmlDocument
-- Insert using openxml allows us to read the structure
insert into #Customer
select
FirstName = XmlFirstName,
LastName = XmlLastName
from openxml (@XmlDocumentHandle, '/ROOT/Customer',2)
with
(
XmlFirstName varchar(20) 'FirstName',
XmlLastName varchar(20) 'LastName'
)
where (XmlFirstName = 'Will' and XmlLastName = 'Smith')
-- Cleanup xml document
exec sp_xml_removedocument @XmlDocumentHandle
-- Show the data
select *
from #Customer
-- Drop tmp table
drop table #Customer
XML 파일을 다음 위의 같은 것을 수행하는 저장 프로 시저를 정의하고 다음 당신에게 제공해야 문자열로 저장 프로 시저 전체 XML 파일의 내용을 전달, C#을 사용하는 경우 기존 테이블에 xml을 가져 오는 상당히 간단한 방법.