Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save colinangusmackay/3035858 to your computer and use it in GitHub Desktop.
Save colinangusmackay/3035858 to your computer and use it in GitHub Desktop.
A T-SQL script that renders media wiki markup of a list of tables or views that can be used in the creation of a data dictionary. More details on my blog: http://colinmackay.co.uk/2012/06/14/creating-a-data-dictionary-with-sql-server-and-mediawiki-part-on
-- For more information about this script and its uses, visit:
-- http://colinmackay.co.uk/2012/06/14/creating-a-data-dictionary-with-sql-server-and-mediawiki-part-one-a-list-of-tables/
DECLARE @Type NVARCHAR(100) = 'BASE TABLE' -- 'VIEW' OR 'BASE TABLE'
DECLARE @catalogue SYSNAME;
DECLARE @schema SYSNAME;
DECLARE @name SYSNAME;
SET NOCOUNT ON
PRINT '{| class="wikitable sortable"
|-
! scope="col" | Schema
! scope="col" | Table
! scope="col" class="unsortable" | Notes
'
DECLARE table_cursor CURSOR FOR
SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE=@Type
ORDER BY TABLE_SCHEMA, TABLE_NAME;
OPEN table_cursor
FETCH NEXT FROM table_cursor
INTO @catalogue, @schema, @name
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT '|-
| '+ @schema+'
| [[' + @catalogue + '.'+@schema+'.'+@name + '|'+ @name+']]
|
'
FETCH NEXT FROM table_cursor
INTO @catalogue, @schema, @name
END
PRINT '|}'
CLOSE table_cursor;
DEALLOCATE table_cursor;
SET NOCOUNT OFF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment