Skip to content

Instantly share code, notes, and snippets.

@asears
Created February 24, 2017 21:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save asears/38a001e71bf95c322d263c3f47b08c29 to your computer and use it in GitHub Desktop.
Save asears/38a001e71bf95c322d263c3f47b08c29 to your computer and use it in GitHub Desktop.
Create markdown based on table metadata in SQL Server / SQL DW / Azure SQL
select 'header' as tablename,0 as colid, '|id|name|type|length|' as markdown
UNION ALL
select 'header2' as tablename, 0 as colid, '|---|---|---|---|' as markdown
UNION ALL
select o.name as tablename, c.colid, convert(varchar(10),c.colid) + '|'+c.name+'|'+ t.name +'|' + convert(varchar(10),c.length) + '|' as markdown
from sysobjects o
inner join syscolumns c on c.id = o.id
inner join systypes t on t.xtype = c.xtype
where o.name = 'mytable'
order by tablename, colid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment