convert database table into XML schema file

喜你入骨 提交于 2021-02-06 09:33:09

问题


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:


I've found this. Give it a try

Select CourseID, Name, CoursePrice
FROM CouseMaster.Course Course
FOR XML AUTO, XMLSCHEMA



回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/828549/convert-database-table-into-xml-schema-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!