Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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