Monday, July 26, 2010

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

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).