convert database table into XML schema file

后端 未结 3 1072
萌比男神i
萌比男神i 2021-02-06 18:50

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)?

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-06 19:23

    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.

提交回复
热议问题