Generating an XML Schema of SQL Server 2005 Database

I was told to generate an XML Schema of an SQL Server 2005 Database. And naturally I started googling it out so I found this at a blog given by the URL at the bottom.

Thumbs up to ya my friend!

create table Person
Age int not NULL check( Age > 0) ,
Height numeric(10,2) not NULL check( Height > 5),
Gender varchar(5) not null check( Gender in (‘M’, ‘F’, ‘O’)),
BirthDate datetime null,
DECLARE @schema xml
SET @schema = (SELECT * FROM Person FOR XML AUTO, ELEMENTS, XMLSCHEMA(‘PersonSchema’))
select @schema


Author: Imran Akram

A .NET/SharePoint Consultant and a political enthusiast who believes in putting the feet of the elected and/or unelected officials to fire in order to get good governance.

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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