The two stored procedures below will help with automating the generation and maintenance of a database data dictionary.
If you provide a description for each database field in a SQL Database, these stored procedures can be used to extract that description information together with some other useful column details.
The first stored proc simply details the column information for a single table:
CREATE PROCEDURE uxp_Table_Data_Dictionary
@Table_Name varchar(50)
AS
@Table_Name varchar(50)
AS
— Extract the table data dictionarySELECTTABLE_NAME,
ORDINAL_POSITION,
COLUMN_NAME,
CASE DATA_TYPE
WHEN ‘varchar’ THEN ‘varchar(‘+CAST(CHARACTER_MAXIMUM_LENGTH AS VARCHAR(20))+’)’
ELSE DATA_TYPE
END AS DATA_TYPE,
ISNULL(COLUMN_DEFAULT, ”) AS COLUMN_DEFAULT,
IS_NULLABLE,
value AS PROPERTY_VALUEFROM
INFORMATION_SCHEMA.COLUMNS AS info
JOIN ::fn_listextendedproperty (NULL, ‘user’, ‘dbo’, ‘table’, @Table_Name, ‘column’, default) AS extended ON info.COLUMN_NAME = extended.objnameWHERE
TABLE_NAME = @Table_Name
The second stored procedure extends this a little and reports the column information for all user tables within the current database:
CREATE PROCEDURE uxp_System_Data_Dictionary
AS
AS
— Create a cursor containing all user tablesDECLARE @tableName varchar(40)DECLARE table_cursor CURSOR FORSELECT name FROM sysobjects WHERE type = ‘U’ AND name <> ‘dtproperties’OPEN table_cursor— Perform the first fetch.FETCH NEXT FROM table_cursor INTO @tableName— Check @@FETCH_STATUS to see if there are any more rows to fetch.WHILE @@FETCH_STATUS = 0BEGIN— Execute the table data dictionary generatorEXEC uxp_Table_Data_Dictionary @tableName— Fetch the next tableFETCH NEXT FROM table_cursor INTO @tableName
END— Tidy Up
CLOSE table_cursor
DEALLOCATE table_cursor
Introduction to Data Wrangler in Microsoft Fabric
What is Data Wrangler? A key selling point of Microsoft Fabric is the Data Science
Jul
Autogen Power BI Model in Tabular Editor
In the realm of business intelligence, Power BI has emerged as a powerful tool for
Jul
Microsoft Healthcare Accelerator for Fabric
Microsoft released the Healthcare Data Solutions in Microsoft Fabric in Q1 2024. It was introduced
Jul
Unlock the Power of Colour: Make Your Power BI Reports Pop
Colour is a powerful visual tool that can enhance the appeal and readability of your
Jul
Python vs. PySpark: Navigating Data Analytics in Databricks – Part 2
Part 2: Exploring Advanced Functionalities in Databricks Welcome back to our Databricks journey! In this
May
GPT-4 with Vision vs Custom Vision in Anomaly Detection
Businesses today are generating data at an unprecedented rate. Automated processing of data is essential
May
Exploring DALL·E Capabilities
What is DALL·E? DALL·E is text-to-image generation system developed by OpenAI using deep learning methodologies.
May
Using Copilot Studio to Develop a HR Policy Bot
The next addition to Microsoft’s generative AI and large language model tools is Microsoft Copilot
Apr