Skip to content

Instantly share code, notes, and snippets.

@benwong
Created July 1, 2012 23:27
Show Gist options
  • Save benwong/3030005 to your computer and use it in GitHub Desktop.
Save benwong/3030005 to your computer and use it in GitHub Desktop.
T-SQL to generate xml of table columns
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