I'm using SQL Server 2008 R2 and have a simple table with a column of data type XML
. I have created an XML Schema document that correctly validates the XML data that will be stored. My questions are:
How can I assign the schema to column such that it will validate the XML and reject the insert if it fails the schema?
Is the schema required in order to add an XML Index to the column or can XML Indices be added without the schema doc?
To create a schema collection, you can use the following:
CREATE XML SCHEMA COLLECTION MyXmlSchema AS
N'YourSchemaHere';
Then, apply it with:
CREATE TABLE MyTable
(
MyTableId INT PRIMARY KEY
, XmlData XML (MyXmlSchema)
)
Referenced from: http://technet.microsoft.com/en-us/library/ms176009.aspx
This example shows you do not need to have a schema on your XML for you to be able to index the column: http://msdn.microsoft.com/en-us/library/bb510443.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With