Instantly share code, notes, and snippets.

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