Generate Schema (.xsd) from MS SQL Server Table

November 2nd, 2010 § Leave a Comment

I just had to extract the schema from a MS SQL server database table today and it was as easy as running this query:

DECLARE @schema xml
SET @schema = (SELECT * FROM TableName FOR XML AUTO, ELEMENTS, XMLSCHEMA(‘SchemaOutputName‘))
select @schema

Just save the output to a file with .xsd extension and there you have it.

Advertisement

Tagged: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading Generate Schema (.xsd) from MS SQL Server Table at TW.

meta

Follow

Get every new post delivered to your Inbox.