• subscribe
October 25, 2010 01:02 PM

Building Dynamic Data Dictionaries

Run these stored procedures
SQL Server Pro
InstantDoc ID #125905
Downloads
125905.zip

Recently I was working on a new database design for a client, and I was asked to prepare a data dictionary of the database. Instead of creating a dedicated single-use document containing the data dictionary, I thought it might be more convenient to design a general mechanism for generating data dictionaries in a database. Such logic could be encapsulated within stored procedures, and the logic would be reusable.

In terms of output, I thought it would be helpful to see the dictionary information in the form of an online SQL Server Reporting Services (SSRS) report. In this way, a data dictionary could be hosted on a company’s departmental reports site, and different team members could refer to the data dictionary report as needed. In addition, because SSRS allows reports to be saved in Microsoft Excel, Microsoft Word, XML, and other formats, the data dictionary information could easily be exported into another report or document.

In this article I present a set of stored procedures that you can use to generate a data dictionary of schemas and tables within a database. I also introduce a simple SSRS report that you can use to publish the data dictionary online. I tested the accompanying code in SQL Server 2008; it also works in SQL Server 2005.

Background

All data dictionary information within SQL Server is set and accessed through extended properties. According to SQL Server Books Online (BOL), extended properties let you “add text, such as descriptive or instructional content, add input masks, and add formatting rules as properties of objects in a database or of the database itself. For example, you can add an extended property to a schema, a schema's view, or to a column in the view. Because extended properties are stored in the database, all applications reading the properties can evaluate the object in the same way. This helps enforce consistency in the way data is treated by all the programs in the system.”

Extended properties have several different levels.  SQL Server BOL explains these levels as follows: “For specifying extended properties, the objects in a SQL Server database are classified into three levels: 0, 1, and 2. Level 0 is the highest level and is defined as objects that are contained at the database scope. Level 1 objects are contained in a schema or user scope, and level 2 objects are contained by level 1 objects. Extended properties can be defined for objects at any of these levels.”

To set an extended property, you use a T-SQL command such as sp_addextendedproperty (to add a new property) or sp_updateextendedproperty (to update an existing property). Similarly, you use the sp_dropextendedproperty command to drop an existing extended property in the database.



ARTICLE TOOLS

Comments
  • christopher
    2 years ago
    Dec 02, 2010

    Thank you for your time and sharing this with all of us. I know it takes a good bit of time to come up with tools like these as well as type up how to use it.

  • Jakob
    2 years ago
    Nov 24, 2010

    NOTE: As mentioned by one of the posters above, the "Download the Code" archive on this site may be missing some of the stored procedures and the SSRS report described in this article. You can download these items here:

    http://www.zgrafsoftware.com/resume/PUBLICATIONS/BuildingDynamicDataDictionaries.zip

    Thank you,

    John Jakob
    john_jakob@hotmail.com

  • Fraser
    2 years ago
    Nov 18, 2010

    Where's the code for the report?

  • Jakob
    2 years ago
    Nov 18, 2010

    >> Where's the code for the report?
    >> Fraser 11/18/2010 11:21:58 AM

    Hi Fraser,
    Looks like the editors didn't include my SSRS report code in the "Download the Code" archive above.
    If you send me an e-mail, I will mail you a ZIP file that contains the report code.
    Thank you,
    John Jakob
    john_jakob@hotmail.com

  • Jakob
    2 years ago
    Nov 18, 2010

    >> Where's the code for the report?
    >> Fraser 11/18/2010 11:21:58 AM

    Hi Fraser,
    Looks like the editors didn't include my SSRS report code in the "Download the Code" archive above.
    If you send me an e-mail, I will mail you a ZIP file that contains the report code.
    Thank you,
    John Jakob
    john_jakob@hotmail.com

You must log on before posting a comment.

Are you a new visitor? Register Here