Created
February 8, 2021 22:04
-
-
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
This file contains 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
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