Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to convert a sql table to Annotated XSD Schema

Author  Topic 

Swati Jain
Posting Yak Master

139 Posts

Posted - 2008-07-11 : 03:30:33
Hello All,



How to convert a sql table to Annotated XSD Schemas



Suppose a table is having columns FirstName,LastName,ConID

How to convert this into

Annotated XSD Schemas as follows

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<xsd:element name="Contact" sql:relation="Person.Contact" >
<xsd:complexType>
<xsd:sequence>
<xsd:element name="FName"
sql:field="FirstName"
type="xsd:string" />
<xsd:element name="LName"
sql:field="LastName"
type="xsd:string" />
</xsd:sequence>
<xsd:attribute name="ConID"
sql:field="ContactID"
type="xsd:integer" />
</xsd:complexType>
</xsd:element>
</xsd:schema>
please suggest any tool or link

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-07-11 : 04:10:33
look at this example:

create table ClientAttributes
(
Age int not NULL check( Age > -1) ,
Weight numeric(10,2) not NULL check( Weight > 0),
Handed varchar(5) not null check( Handed in ('left', 'right')),
QuitDate datetime null,
HasInsurance bit not null default(1)
)

go
-- create an XML schema from the table with client attributes
DECLARE @mySchema xml

-- this is the default schema that gets created from the ClientAttributes table
-- however the check constraints aren't converted
SET @mySchema = (SELECT * FROM ClientAttributes FOR XML AUTO, ELEMENTS, XMLSCHEMA('ClientAttributes'))
-- see the schema that gets auto-created
select @mySchema


_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.0 out!
Go to Top of Page
   

- Advertisement -