SQL Server XML Query Example for Database Developer
In this SQL XML Query example, T-SQL developers will see SQL XML enhancements introduced first with Microsoft SQL Server 2005 related with SQL XML features like XML data type, XML queries.
A SQL database developer who is good at understanding and querying XML data for filtering out required information will easily query JSON data too. On this SQL tutorial as database programmer we will focus on SQL XML query, to query JSON on SQL Server please refer to given tutorial link.
Let's start first by defining a sample sql xml structure which contains a list of SQL programming and administration books within XML tags.
Now, sql developers can save this XML file on SQL Server machine on root of C drive with the name sql-books.xml
Second step for sql developers will be reading XML file using sql code and import xml data into an sql xml variable.
Not let's define the variable @xml as XML sql data type.
Then import XML data using SQL OPENROWSET command.
SQL database developer can now build sql select statements which returns the list of sql books by reading XML data.
Here is a sql xml example query.
The t-sql XML query output is as follows in the following screenshot: