Click here to Skip to main content
15,884,425 members
Articles / Database Development / SQL Server
Tip/Trick

Create Documentation for SQL Server Tables

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
27 Jun 2011CPOL2 min read 22.4K   680   18   3
This tool reads the descriptions of the columns of the SQL server and creates a Word document using SoftArtisans' WordWriter.

CreateDoc_SQLServerTables/CreateDoc_small.gif

Introduction

This post presents a tool that creates a Word document that contains the schema information of the tables in a SQL server database. It uses SoftArtisans' OfficeWriter. In SQL server, descriptions can be given to columns. Therefore, the documentation can be kept on the SQL server, and with this tool, it may be exported to a Word document.

Background

The documentation of the database is a delivery item in IT projects. This tool creates this documentation automatically, provided the description of the columns is filled-in in the SQL server database.

Using the Code

Compile the project and run it. A form appears, where you may edit the connection string, and the paths to the input and output files. A sample input file is already provided. Press the button Refresh and the list of tables in the database should appear in the grid. Select the tables for which you want the documentation to be created, and press the button Create Doc. The tool will read the InputFile, append the documentation of the selected tables, and will write the resulting file to OutputFile. Upon finishing, the OutputFile is opened. Unfortunately, you must have SoftArtisan's OfficeWriter installed.

Form1 has a PropertyGrid to which the project settings are bound. This enables the user to change the connection string, and the paths to the input and output files. Form1 has also a DataGridView to which a dataset is bound. The project has the typed dataset TablesData, which is filled with the list of all tables in the database (except the ones containing the word audit). Upon pressing the button Create Doc, the code loops through all tables and fills the typed dataset PropertiesData with the column information of each table (method FillTableInfo). A new paragraph of style Heading 1 is created for each table. Rows in PropertiesData that have the field ColumnName empty, are considered table documentation and are written first to the Word document (method WordDocDescriptionFill). Then a table is appended, some formatting is applied (method WordTableFormat), the header row is filled-in (method WordTableHeaderFill) and finally the body of the table is filled-in with the column information in PropertiesData dataset (method WordTableBodyFill).

Points of Interest

It might be possible to use Microsoft Word to do this, but I had already used OfficeWriter in another project.

History

  • 27th June, 2011: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Unisystems
Greece Greece
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
SuggestionCoding Pin
Luis Oliveira 19666-Nov-11 12:16
Luis Oliveira 19666-Nov-11 12:16 
QuestionBased on commercial product? Pin
HaBiX27-Jun-11 21:17
HaBiX27-Jun-11 21:17 
QuestionCore logic code snippets & Explanation Pin
Md. Marufuzzaman27-Jun-11 5:49
professionalMd. Marufuzzaman27-Jun-11 5:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.