We're Hiring!
Take the next step in your career and work on diverse technology projects with cross-functional teams.
LEARN MORE
Mountain West Farm Bureau Insurance
office workers empowered by business technology solutions
BLOG
1
3
2014

SQL SERVER Data Dictionary on a Shoestring budget

Last updated:
8.10.2021

As a developer you begin a new project and one of the most important things to come up to speed on is the data model for the project. You ask around about where you might find data dictionary documentation and you get several answers including:

· Ask the DBAs, they might know where it is kept.

· If there is any documentation it should be out on the SharePoint site.

· There wasn’t enough time allocated in the project to let us build this out.

· The project didn’t have any budget to purchase any tools to produce a data dictionary.

This can be rather frustrating especially when you need to understand the data in the database in order to be productive at the tasks you have been given for the project. If you could just have some current meaningful table and column descriptions that would go a long way to help you come up to speed.

The following simple approach can be incorporated into any project that uses SQL Server as its database.

Step 1 – Make the data dictionary be part of your database

SQL Server allows for the use of extended properties on many objects in the database including tables and columns. In SQL Server Management Studio (SSMS), simply right click on any table to see its properties. Extended Properties is the section to select in order to see any current defined properties or to add any new properties. The main thing is to standardize your property names like “Description” for any comments. For data warehouse projects another nice property to add would be “Source” to track the source mapping of where the data came from to populate the table. Both of these properties work well for columns also.

clip_image002_thumb_2.jpg

SSMS is probably not the most convenient place for entering the descriptions. It would be better if the descriptions were in the DDL. Luckily we have T-SQL functions to add and update extended properties.

Step 2 – Add the Extended Properties to the DDL Scripts

The T-SQL function for adding an extended property is sys.sp_addextendedproperty.

Table Example

EXEC sp_addextendedproperty @name=N'Description', @value=N'Job Queue provides a queuing mechanism for executing jobs in the order of priority for a given group of Jobs.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'JobQueue'

GO

Column ExampleEXEC sp_addextendedproperty @name=N'Description', @value=N'Indicates which Jobs are queued to executed (Q), executing (E), completed (C) execution or failed (F) execution.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'JobQueue', @level2type=N'COLUMN',@level2name=N'ProcessingInd'

GO

The key parameters have been highlighted. For a further explanation and more examples see: http://msdn.microsoft.com/en-us/library/ms180047.aspx

It is worth noting that if you manage your database DDL as Visual Studio database project that the database migration scripts to an excellent job of handling updates to extended properties by producing scripts that use sys.sp_updateextendedproperty.

Step 3 – Extract the Extended Properties to Create the Data Dictionary Documentation

Now that you have the properties stored in the database, you can easily retrieve them out using the fn_listextendedproperty function. The following example will select all table extended properties in the dbo schema. To limit this just to the extended property of “Description”, a filter can be added.

SELECT objname, name, value

FROM fn_listextendedproperty(NULL, 'schema', 'dbo', 'table', default, NULL, NULL)

To extract specific extended properties, just add the filter to the property you need such as WHERE name = 'Description'.

Column descriptions can be obtained utilizing fn_listextendedproperty with a slightly different set of parameters. In the example below, the table name is added along with the parameter of “column” to get the list of column extended properties.

SELECT objtype, objname, name, value

FROM fn_listextendedproperty (NULL, 'schema', 'dbo', 'table', 'JobQueue', 'column', default);

To extract specific extended properties, just add the filter to the property you need such as WHERE name = 'Description'.

For a further explanation on fn_listextendedproperty and more examples see: http://technet.microsoft.com/en-us/library/ms179853.aspx

Now all it takes is to take the output from the above commands and format it into CSV for Excel or as HTML. Here is a small sample of HTML output.

clip_image004_2.jpg

As you can see with a little work, you can keep an up-to-date data dictionary available in SSMS and in a document form that doesn’t cost a huge amount of money. In future posts, I can provide more details on the SQL script that was used to generate the HTML document.

Recent Blog Posts

lunavi logo alternate white and yellow
11.19.2024
11
.
8
.
2024
Load & Performance Testing with Azure Load Testing Service

Learn about load and performance testing in Microsoft Azure.

Learn more
lunavi logo alternate white and yellow
10.8.2024
09
.
25
.
2024
Maximizing Business Efficiency with Azure DevOps

For enterprises looking to adopt or mature their DevOps practices, Azure DevOps offers unmatched flexibility, scalability, and depth.

Learn more
lunavi logo alternate white and yellow
10.8.2024
09
.
09
.
2024
Exploring Microsoft Fabric: A Comprehensive Overview

Discover how Microsoft Fabric transforms data management and analytics with powerful tools for real-time insights and seamless collaboration, driving smarter, faster business decisions.

Learn more