SQL Server 2005 introduces a local data type called XML. You can create a table with one or more XML columns in addition to the relational columns. Variables and parameters are also allowed. To better support XML model features (such as document order and recursive structure), XML
attributes
Modifying the attribute value is also very common. For example, to change the ID attribute of the book node whose ID is 0001 to 0005, we can use the following code:
-- Modify attributes
Set @ xmldoc. Modify ('replace value of (root/book [@ ID = "0001"]/@ ID) [1] with "0005 "')
Select @ xmldoc. Query ('(/root/book) [1]')
Running result
After the above learning, I believe you can use the XML type in SQL
then we can break down each point of the key.Partitioning is to split a table data into sub-collections, that is, to split a data file into multiple data files, but the storage of these files can rely on a filegroup or multiple filegroups, because more than one filegroup can increase the database access concurrency, but also can be different partitions configured to different disks to improve efficiency , the recommended partition is created with the same number of filegroups.1. Create filegrou
' Zao ', N ' ovens 'UNION ALL select ' Ze ', N ' 稄 'UNION ALL SELECT ' Zei ', N ' 鱡 'UNION ALL SELECT ' Zen ', N ' 囎 'UNION ALL select ' Zeng ', N ' giveaway 'UNION ALL SELECT ' Zha ', N ' winepress 'UNION ALL SELECT ' Zhai ', N ' partners 'UNION ALL SELECT ' Zhan ', N ' 驏 'UNION ALL select ' Zhang ', N ' 瞕 'UNION ALL select ' Zhao ', N ' 羄 'UNION ALL SELECT ' Zhe ', N ' 鷓 'UNION ALL select ' Zhen ', N ' gloom 'UNION ALL select ' Zheng ', N ' certificate 'UNION ALL select ' Zhi ', N ' 豒 'UNION
displayed by means of a digital index:SELECT info_untyped.query ( '/people/person[1]/firstname ') as people_untyped, info_typed.query ( ' Declare namespace ns= "Urn:clientinfonamespace"; /ns:people/ns:person[2]/ns:firstname ') as People_typedfrom clientinfo;Listing 15: Using a numeric index to refer to the results under an elementThe value () method of XMLAs simple as the query () method, many times when you want to retrieve a particular element or attribute, instead of getting the
results6 , modify PropertiesModifying property values is also very common, such as modifying the ID property of the book node with ID 0001 to 0005, which we can use as follows:--Modify propertiesSet @xmlDoc. Modify (' Replace value ' of (root/book[@id = "0001"]/@id) [1] with "0005" ')Select @xmlDoc. Query (' (/root/book) [1] ')Run resultsOK, after the study above, I believe you can already use the XML type in SQL
Copy Code code as follows:
/*01.
Introduction to 02.sql XML:
--by Jinjazz
--http://blog.csdn.net/jinjazz
05.
06.1, XML: Ability to recognize elements, attributes, and values
07.
08.2, XPath: Addressing language, lookup similar to Windows directory (go to the wall if you don't use the dir command)
09.
10. Syntax format, which can be comb
work is to import an actual XML file to the SQL and process it. (It's amazing why this is not a key part in all the BOL examples ). (I must thank my colleague Billy Pang for his help. He helped me solve the problem and gave the code-although I have cut the code out of this article. Thank you, Billy !) The basic technique is to read files row-by-row by text. Connect all read rows to a large
stream the XML output.
This feature is best saved to a stored program because the pointer is slower and a stored program is edited in advance. The following is the stored program that completes this task (Transact SQL).
DECLARE @employee_id intDECLARE @fname varchar (50)DECLARE @lname varchar (50)DECLARE phone_cursor
code to delete the ID attribute of the book node whose ID is 0001:
-- Delete attributes
Set @ xmldoc. Modify ('delete root/book [@ ID = "0001"]/@ id ')
Select @ xmldoc. Query ('(/root/book) [1]')
Running result
6Modify attributes
Modifying the attribute value is also very common. For example, to change the ID attribute of the book node whose ID is 0001 to 0005, we can use the following code:
-- Modify attributes
Set @ xmldoc. Modify ('replace value of (root/book [@ ID = "0001"
remaining work is to import an actual XML file to the SQL and process it. (It's amazing why this is not a key part in all the BOL examples ). (I must thank my colleague Billy Pang for his help. He helped me solve the problem and gave the code-although I have cut the code out of this article. Thank you, Billy !) The basic technique is to read files row-by-row by text. Connect all read rows to a large
If you work in it, you probably have heard of XML, but if your job is primarily about SQL Server, you may not be using XML directly. XML is already a popular data format in the Web programming environment, and it is one of the main underlying technologies in the. NET framework. SQL
)') astitle from @data. Nodes ('Bookstore') asTab (Col)--16. Get the first author of each bookSelectTab.Col.value ('Author[1]','varchar (max)') astitle from @data. Nodes ('//book') asTab (Col)--17. Get all the information of all bookSelectT.c.value ('Title[1]','varchar (max)') astitle, T.c.value ('Year[1]','int') as Year, T.c.value ('Title[1]','varchar (max)') a
is not enough text in this article to describe the parameters that OpenXML received. See Bol for more information. Find OPENXML in Transact-SQL Reference.
Now we have reached the final step. All that remains is to import an actual XML file into the SQL and process it (very fast why none of the BOL examples involve this critical part).
(I must thank my colleague
productid,100 as quantityUNION ALLSelect 124,2,20UNION ALLSelect 125,3, 5),ProductAs(Select 1 as Id,n ' leewhoeeuniversity ' as nameUNION ALLSelect 2,n ' DePaul ')SELECT * FROM [order],product where [order].productid=product.id FOR XML auto
Results:
Of course, Auto mode can also specify Elements,binary BASE64, with Raw. (XML query in SQL Server: FOR
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.