如何将表架构转换为 XML 格式?格式如下。
<Tables>
<Table>
<Name>courses</Name>
<Schema>dbo</Schema>
<Columns>
<Column>
<Name>id</Name>
<DataType>int</DataType>
</Column>
<Column>
<Name>page_name</Name>
<DataType>nvarchar</DataType>
<Length>50</Length>
</Column>
</Columns>
</Table>
<Table>
<Name>course_details</Name>
<Schema>dbo</Schema>
.....
.....
</Table>
</Tables>
我能够分别生成列和表的结构。但我想合并两者。这怎么可能?我的 SQL 脚本
对于表:
SELECT
Distinct
TABLE_NAME as Name,
TABLE_SCHEMA as [Schema]
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA='dbo'
ORDER BY TABLE_NAME ASC
For XML PATH ('Table'),
Root('Tables')
对于列:
SELECT
Column_Name as Name,
DATA_TYPE as DataType,
CHARACTER_MAXIMUM_LENGTH as [Length]
FROM INFORMATION_SCHEMA.COLUMNS
For XML PATH ('Column'),
Root('Columns')