SQL: Getting XML Schema from MS SQL Database

http://stackoverflow.com/questions/298660/getting-xml-schema-from-ms-sql-database

It is possible to generate a XML Schema from a Database?

It sure is, XMLSpy can generate XML Schema from a database.

There’s another way, though I’ve never tested it:

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

one more example

DECLARE @schema xml

SET @schema = (SELECT * FROM Company FOR XML AUTO, ELEMENTS, XMLSCHEMA(‘CompanySchema’))

select @schema

Advertisements

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 )

Google+ photo

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

Connecting to %s