Manually preparing a data dictionary document will take ages in MS Word which contains 100's of tables, stored procedures, functions, triggers, views, indexes, etc. in
a SQL Server database as you need to type each and every column of the table along with the associated dependencies. I need a data dictionary document which generates the database schema automatically in one click with nice formatting. For this I did
a lot of research in Google to find the solution and finally I wrote my own code to do this functionality and
I thought to share my experience with you all.
The main purpose of this article is to generate the data dictionary document automatically by simply running the macro code in MS Word within seconds.
I am not a VBA guru but I still started doing some kind of researching on VBA code in Google
and I got ideas from different forums, many thanks to those people who posted their ideas.
I hope this solution will help you to prepare a data dictionary document. Here we start...
Basically, this code will prepare for you the following information in the document. The
table name with the following dependent information:
- Table Column Details
- Stored Procedures
- Primary Keys
- Foreign Keys
- Default Constraints
- Identity Columns
Using the code
Following are the steps to run this code:
- Simply open a blank Word document (it is mandatory).
- Go to menu Tools->Macro->Macros->Create, this will create a new Visual
Basic module editor.
- Paste this code.
- Change the connection string as per your SQL Server credentials (it is mandatory).
- Add references to Microsoft ActiveX Data Objects Library from the menu Tools->References.
- Run the macro by pressing F5 from the VBA editor.
Points of Interest
This code will generate the data dictionary document automatically with one click and it is simple to use this code.