Question

As a first step to adding our SQL objects to version control I've written a script that will query sys.objects, sys.modules to script out all objects as CREATEs. I used an example from here to script out my tables. The goal is to preserve the change history of our SQL objects and eventually automate SQL steps we currently achieve manually. Now I need to script out XMLSchemaCollections as a CREATE but I haven't had luck finding an example of how. I imagine it would include querying the several sys.xml_schema_* tables and piecing the XML together element by agonizing element. Does anyone have a working example of how to achieve this?

NOTE: The requirement is to achieve this through a SQL script, not a 3rd party component (i.e. RedGate) nor a Visual Studio Database Project.

Was it helpful?

Solution

You can use the function xml_schema_namespace (Transact-SQL)

Reconstructs all the schemas or a specific schema in the specified XML schema collection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top