In this article we will read about xml data type and also read advantages and limitations of xml data types over the relational data types.Create a table with XML data type: In the above query we created an Employee_Details table, first column(id) of this table is integer type and second column(Employee_Data) is xml type.The result of the nodes() method contain a rowset that has logical copies of the original XML instances.In these logical copies, the context node of every row instance is set to one of the nodes identified with the query expression, so that subsequent queries can navigate relative to these context nodes. In the above table we can see that first two rows contain two employee instances.The nodes() Method: The nodes() method is used to shred XML into multiple rows to propagate parts of XML documents into rowsets.It allows us to identify nodes that will be mapped into a new row.
Before xml date type the xml data was stored in varchar or text data type, that was proven to be poor in terms of querying and manipulating the XML data.
We will store the details of employee as xml formatted in Employee_Data column.
Insert Data into table Let us suppose that we are retrieving data of employees in xml format.
In the above query we inserted the record of employees in the table.
XML record holds the name, city and salary information of employee.