TAILIEUCHUNG - Beginning C# 2005 Databases From Novice to Professional phần 10

T-SQL cung cấp một thủ tục lưu trữ, sp_xml_preparedocument, để phân tích các tài liệu XML. OpenXML làm việc với các cây DOM trong bộ nhớ mà sp_xml_preparedocument sản xuất. | CHAPTER 17 USING XML 443 T-SQL provides a stored procedure sp_xml_preparedocument to parse XML documents. OPENXML works with the in-memory DOM tree that sp_xml_preparedocument produces. Tip You can use another stored procedure sp_xml_removedocument to free the DOM tree from memory. We don t need to do this for our simple examples. Since you need to parse an XML document with sp_xml_preparedocument before you can use it with OPENXML you ll use the XML document that FOR XML AUTO substantially matched since it s the kind of XML design that T-SQL handles most easily states state abbr CA name California city name Berkeley city name Los Angeles city name Wilmington state state abbr DE name Delaware city name Newark city name Wilmington state states and which we provide in the file. Try It Out Using OPENXML In Figure 17-1 you displayed the state and city to check that you d loaded the tables. The XML document in accurately represents this data so you want to see if you can query it instead of the tables and get the same results 1. Create a stored procedure named xml2tbl in the Northwind database with the T-SQL in Listing 17-5. 444 CHAPTER 17 USING XML Listing 17-5. Creating the xml2tbl Stored Procedure use northwind go create procedure xml2tbl @xdoc xml as declare @xdocp int exec sp_xml_preparedocument @xdocp output @xdoc select sabbr sname cname from openxml @xdocp states state city 0 with sabbr char 2 . @abbr sname varchar 20 . @name cname varchar 20 @name 2. Replace the code in the edit window with that in Listing 17-6 which provides the XML document and runs the query. You should see the results shown in Figure 17-5 and they should be the same results as in Figure 17-1. Listing 17-6. Running the xml2tbl Stored Procedure declare @xdoc xml set @xdoc states state abbr CA name California CHAPTER 17 USING XML 445 city name Berkeley city name Los Angeles city name Wilmington state state abbr DE name Delaware city name Newark city name Wilmington state

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.