How can I get an XML Schema (XSD) from SQL Server?

To obtain the XSD for the ‘Order’ table, use the query: Select * from [order] where ID < 0 FOR XML AUTO, XMLSCHEMA. This approach ensures that the XSD is returned since the WHERE clause conditions prevent any order records from being retrieved.


This question has come up a few times, so here is the answer…

Example: To retrieve the XSD for the ‘Order’ table you can run:
Select * from [order] where ID < 0 FOR XML AUTO, XMLSCHEMA

This will just return the XSD (as the where clause will not return any order records).

Discover more from Liquid Technologies Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading