How to alter existing xml schema collection in ms sql

Microsoft SQL Server does not allow to replace an existing XSD schema in a straight forward manner. There is a way of extending a schema by adding new schema component to an existing collection but it will not help if we need to replace a schema:

ALTER XML SCHEMA COLLECTION [relational_schema.]sql_identifier ADD 'Schema Component'

We cannot drop the schema collection and recreate it as it might be used by a table. The way forward would be to untype all XML columns using the collection, then drop and recreate the schema collection and as a last step type the XML columns to that new schema collection:

ALTER TABLE my_table ALTER COLUMN my_xml_column XML

DROP XML SCHEMA COLLECTION my_xml_collection

CREATE XML SCHEMA COLLECTION my_xml_collection AS 'content of my XSD'

ALTER TABLE my_table ALTER COLUMN my_xml_column XML(my_xml_collection)

Popularity: 27% [?]

1 Comment »

  1. ROMBrecht said,

    September 29, 2009 @ 2:34 pm

    How would you do the same thing for a stored procedure without having to repeat the stored procedure code?

RSS feed for comments on this post · TrackBack URI

Leave a Comment

Close
E-mail It