Database Reference
In-Depth Information
How It Works
This works in the same way that the
CREATE TABLE
statement is expected to work without the
xml
datatype. Though I've said the
xml
datatype is different from other SQL Server datatypes, columns of
xml
type are defined just like any other columns. (But they can't be used in primary keys.)
Now, you'll insert your XML documents into
xmltest
and query it to see that they were stored.
Try It: Storing and Retrieving XML Documents
To insert your XML documents, follow these steps:
1.
Replace the code in the SQL edit window with the code in Listing 7-1.
Listing 7-1.
Inserting XML Documents into xmltest
insert into xmltest
values(
1,
'
<states>
<state>
<abbr>CA</abbr>
<name>California</name>
<city>Berkeley</city>
<city>Los Angeles</city>
<city>Wilmington</city>
</state>
<state>
<abbr>DE</abbr>
<name>Delaware</name>
<city>Newark</city>
<city>Wilmington</city>
</state>
</states>
'
)
insert into xmltest
values(
2,
'
<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>