SQL Server XML Schema Collection is an interesting concept and I find it very useful when designing dynamic data content. However as I work my way through implementing Schema Collections, I find it very difficult to maintain them.
Schema Collection DDL allows only CREATE and ALTER/ADD nodes to existing schemes.
CREATE XML SCHEMA COLLECTION [ <relational_schema>. ]sql_identifier AS 'XSD Content'
ALTER XML SCHEMA COLLECTION [ <relational_schema>. ]sql_identifier ADD 'Schema Component'
When you want to remove any node from a schema you have to issue following DDL’s.
- If that schema collection assigned to a table column, you have to alter table to remove schema collection association from that column
- Drop the schema collection object
- Re-Create schema collection
- Alter table column to re-associate schema collection to that column.
This is pain when it comes to 100+ of schemes in a collection. Also you have to re-create XML indexes all over again, if any.
Any solutions, suggestions, tricks to make this schema collection object editing process easier?
I agree with David that XML is not the panacea we were told it would be, but there are some situations where it is either unavoidable or the best tool for the job. Schema maintenance is painful though. I only have a couple to deal with and still lose hours.
This script might help. It generates the table drops and adds you’ll need. It would need to mdified to include UDFs or other objects that might reference the XML schema. To generate the Add schema statements, I suggest you use the “Generate Scripts…” function in the tasks menu in Mgt Studio and save them off for Step 2 of the script.
Hope it helps.