Skip to content

Instantly share code, notes, and snippets.

@aplocher
Created February 8, 2021 22:04
Show Gist options
  • Save aplocher/9b3d061bfbfc44f7adcd244a12548139 to your computer and use it in GitHub Desktop.
Save aplocher/9b3d061bfbfc44f7adcd244a12548139 to your computer and use it in GitHub Desktop.
T-SQL script to generate data dict. markdown to be used in Azure DevOps Wiki from a SQL Server table
use varis_p
go
declare
@table varchar(50) = 'dbo.SomeTable'
select md from (
-- Row 1 - Headers
select
-2 as colid,
'| Name | Type | Nullable | Other Properties | Notes |' as md
union all
-- Row 2 - Underline
select
-1 as colid,
'|-|-|-|-|-|' as md
union all
-- Data rows
select
c.colid,
'| '+ c.name
+' | ' + t.name
+ case when t.name in ('varchar', 'char', 'nvarchar', 'nchar') then '('+ cast(c.length as varchar(50)) +')' else '' end
+' | ' + case when isnullable = 1 then 'yes' else 'no' end
+' |' as md
from sysobjects as o
join syscolumns as c on o.id=c.id
join systypes as t on t.xtype=c.xtype
where o.id=object_id(@table)
) as x
order by colid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment