2

I am using SQL Server 2005. Is there any command or GUI tool (e.g. any menu/function from SQL Server management studio) to convert database table into XML schema file (.xsd)?

thanks in advance, George

1
  • Check this link.... To download an Application to convert a SQL Server database table into XML sites.google.com/site/createxmlfromdb Commented Sep 29, 2012 at 9:03

3 Answers 3

8

I've found this. Give it a try

Select CourseID, Name, CoursePrice
FROM CouseMaster.Course Course
FOR XML AUTO, XMLSCHEMA
Sign up to request clarification or add additional context in comments.

11 Comments

@Mork0075, 1. CourseID, Name, CoursePrice are the column names? 2. I think CouseMaster.Course is the table name, but why you add an additional Course after CouseMaster.Course Course?
This was only a copy and paste snippet. The select and from are not really important, the FOR XML AUTO, XMLSCHEMA should be.
Cool, I am using "Select CourseID, Name, CoursePriceFROM CouseMaster.Course FOR XML AUTO, XMLSCHEMA" and it works. The last question, the additiona Course after CouseMaster.Course means?
I dont know, perhaps its a typo and should be FROM x AS y
@Mork0075, how to output schema to a file?
|
0

You can write to file like this:

bcp.exe "select top 0 * from (select 1 as iCol) as t for xml auto, xmlschema" queryout outfile.xsd -T -c

I'm Using the TOP 0 to exclude the xml of the actual query data since you only want the schema. The -c causes it to be plain character data in the output, use -w instead if you want utf-16 (unicode) output.

EDIT - and if you want to change the xml structure, look at PATH with FOR XML.

Comments

0

Declare @SQL nvarchar(1000) SET @SQL= 'bcp.exe '+ '"select * from yourdbname.yourschema.yourtablename for xml path (''record''), ROOT (''tabel'')"' +' queryout '+ 'c:\yourfilename.xsd' +' -w -r -t -SyourServerName -T'

print @SQL EXEC Master..xp_CmdShell @SQL

Replace allvalues starts with 'your', accordingly

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.