Created
July 1, 2012 23:27
-
-
Save benwong/3030005 to your computer and use it in GitHub Desktop.
T-SQL to generate xml of table columns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare @tableName varchar(50) | |
set @tableName = '[table_name]' | |
select | |
1 as tag, | |
null as parent, | |
table_name as [table!1!table], | |
null as [column!2!colname], | |
null as [column!2!datatype], | |
null as [column!2!length] | |
from information_schema.tables [table] | |
where table_name = @tableName | |
union all | |
select | |
2 as tag, | |
1 as parent, | |
null as [table!1!table], | |
column_name as [column!2!colname], | |
data_type as [column!2!datatype], | |
character_maximum_length as [column!2!length] | |
from information_schema.columns [column] | |
where table_name = @tableName | |
for xml explicit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment