.
RealTimeDocs

Purpose for SQL RealTimeDocs™

It's a tool in .Net and MSSQL to extract useful information from MSSQL Database Servers and display it on a dashboard which can be searched, shared and analyze for efficient and faster database developments.
It provides Following information:

  1. Architecture
  2. Dependencies
  3. Techo-Process Link
  4. Documentation


Architecture


how will you answer these questions?

  • What are the Database Server Properties on which my database is hosted?
  • Is DR configured on a DB server?
  • What is the status of my Scheduled Job? how much time it took to complete?
  • What are the user permissions associated with my database?

To answer these questions, Developers raise a ticket with Admin/DBA team , which they reply via mail. Over the period of time, configuration changes and information provided by DBA over mail becomes outdated. To solve this problem , if we have a Web interface which fetch system information via system catalog views and display in real time, then developer will always have ready to use information about SQL server Architecture and it will help them in efficient and faster decision making.

Architecture

Dependencies

List down technical dependencies on technical objects For eg.

  • A Stored Proc is dependent on how many tables
  • A User Defined Function(UDF) is dependent on how many objects like table, and how many objects depends on this UDF.
  • How many cross database or cross Server dependencies are there in your database

Architecture

Techo-Functional Link

Map Business Process with Technical Objects. It can be used to Answer

  • Modification of 1 Technical Object(Table/SP) will Impact how many processes
  • Modification in 1 Business Process will impact how many Technical Objects(Table/SP)
Developer Need to Maintain Comma Seperated list of Processes in extended properties of SQL Objects like Stored Proc, Views , Functions, Tables, Columns Etc.

Architecture

Documentation

For a programmer reliable documentation is always a must. The presence of documentation helps keep track of all aspects of an application and it improves on the quality of a software product. Its main focuses are development, maintenance and knowledge transfer to other developers. Successful documentation will make information easily accessible, provide a limited number of user entry points, help new users learn quickly, simplify the product and help cut support costs. Documentation is usually focused on the following components that make up an application: server environments, business rules, databases/files, troubleshooting, application installation and code deployment.

Benefits of using SQL RealTimeDocs™

  1. Documentation Stored in Key-Value Pair which is tightly associated with SQL objects it defines and easily retrieved by SQL Catalog Views: sys.extended_properties
  2. Real Time Documentation
  3. Document become a part of development phase
  4. Strict Rules to ensure document is up-to-date and comply agreed format

Documentation

Mandatory Documentation Objects Includes:

  1. Database
  2. Stored Procedure
  3. User Defined Function
  4. Views
  5. Triggers
Optional Documentation Objects Includes:
  1. Constraints
  2. Table
  3. Columns
  4. Indexes

For More Information Go to How to do Documentation

ExtendedProperty
.
RealTimeDocs

How SQL RealTimeDocs™ Works?

It is developed in .Net(frontend) and MSSQL(backend). When the Application Pool is started, It load the configuration from ConnectionData.XML and extract the Substring After the Keyword SQLDocs_ and bind it with the Landscape dropdown of Default Page of application. The Landscape is binded with a Data Source = Your DB Server and it will extract only the Primary Datasource Server. For Monitoring additional Database Server, Kindly maintain a new config in connectiondata.xml

HowItWorks

As shown in image to your right, if DB login User have access and permissions to the DB server i.e.

  • VIEW SERVER STATE
  • VIEW ANY DEFINITION on all user Databases + MSDB + MASTER
  • PUBLIC Role on all user databases
, then that user can extract all the information via Catalog Views. Kindy configure connectionData.xml for servers shown as Red.

HowItWorks
.

Best practices: How to Document

With SQL Server, it is strange how some of the most radical improvements that have been introduced over the years have been slipped in almost unnoticed. Conversely, the features that were plastered all over the marketing brochures are sometimes the ones that turn out to be dead ends.

A feature that fits into the former category is the extended properties of databases. Introduced quietly with SQL Server 2000, one could have easily missed them but they have proved, after all, to be of great value to the developer. Extended properties are the route to creating self-documenting databases. I use the term ‘self-documenting’ in the sense that one can attach the documentation directly to the database itself and its objects, rather than create a separate document. Basically, you use the extended properties of data objects to apply your own properties to the metadata.

The advantage of using the extended properties is that the documentation, notes, and so on stay with the databases and can be used as a “live documentation” mechanism. They are backed up with the database, and scripted out with the build scripts.

In Your Company SQL Server Landscapes, we must follow below Practices to Create a Standard, Self-Updating, Ready-to-go and Single Interface Visibility Documentation for All Teams. To achieve this Purpose, All Teams Must Follow Below Steps

  1. Get Yourself Conversed with SQL Extended Properties. Click here to know Commands
  2. Always Run All the SQL Commands in Following Sequences: Dev-->Test(QA)-->Prod and Verify with Visual Studio Database Schema Comparison Tool (Open .scmp file in VS and compare. For more info about VS-SCMP Click here or Google) VS-SCMP is a part of VS-SSDT Tools and we already have the License
  3. Whenever you Add/Modify SQL Objects(Like SP/Views/Function/Tables etc), always Append Extended Properties Command with original Script like:
    USE [YourDatabasename]
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    
    CREATE PROCEDURE [dbo].[Usp_MyStoredProc]
        @paramList INT
    AS
    BEGIN
        SET NOCOUNT ON;
    	/*
    		Business Logic Goes Here
    	*/
    END;
    GO
    
    /* Following Extended Properites need to be Added  */ 
                                    
    EXEC sys.sp_addextendedproperty @name=N'Purpose', @value=N'Purpose of Usp_MyStoredProc' , @level0type=N'SCHEMA',@level0name=N'dbo' , @level1type=N'PROCEDURE/VIEW/FUNCTION',@level1name=N'Usp_MyStoredProc' GO

Verify Documentation with Architecture-->Documentation in SQL RealTimeDocs™. Kindly check below

First Phase: Documentation is Incomplete

Second Phase: Documentation is Partial

Third Phase: Documentation is Completed

.

What it can't Do

SQL RealTimeDocs™ is a tool to extract Real time information from Microsoft SQL Server System Catalog Views. If the catalog views doesn't have information which user expects then this tool will not be able to answer those queries


For Eg.:

  1. List down all Stored procedure which is unused since last 1 month
    • Because this information is retrieved only if SQL profiler is turned On in Production for 1 month which is a resource intensive activity. However sys.dm_exec_procedure_stats catalog view will display this information since last server Cache refreshed. These activities can flush it: Restart/Recompile/DBCC FREEPROCCACHE/Low Server Memory etc .It display that information which is useful but it is incomplete. Kindly check with admin team for more information.
  2. List down all the SQL objects(SP, Views, Function etc.) managed by other teams which refer my SQL object in my database.
    • Basic Idea is to find out how many teams will be impacted if a particular object is modified. For simplicity, let's focus only on Callee SQL objects which are either
      • Local to your database server
      • Remote SQL Objects which are connected via Link Server.

    It is possible to fetch Cross-Database and Cross-Server reference in our Database which is described as remote objects in our Database but not the other way round. It is equivalent to Finding whom I know [Easy] Vs Who Know me [Very Difficult] . Kindly check sys.sql_expression_dependencies for more details.

    To Find Cross Database dependencies, we have to search sys.sql_expression_dependencies of all Database except your database [MyDB] and find cross database reference of MyDB in them and compile the list. It is doable but Highly Resource Intensive . Current version have Linkserver and Database reference check in all databases of selected database server.

    To Find Cross Server dependencies, we have to search sys.sql_expression_dependencies of all Databases of all Linked Servers except your MyServer-->[MyDB] and find Server reference of MyServer-->MyDB in them and compile the list.
    Since Link server is a one way Route, so if your transactional server doesn't have link to Source Server where callee Object exists, then it will never be shown in your list

  3. Able to get 1-click PowerPoint Presentation of my entire database
    • You reap what you sow is the philosophy of documentation. Server Architecture and Database objects list can be retreived from Architecture and SQL Objects Dropdown respectively. But to define and describe those objects, it require storing that Description/Process-Mapping in Extended Properties. If you have added Extended Properties With Correct Data (Purpose ,Process Mapping and last modified By etc.) , then you'll get tablar format of all the Objects like Database(yes it is also an object), Stored Proc, Views, Functions, Tables etc. with their Key-Value Pair. The tablur format has 2 classification with Search Functionality:
      • Type of Object
        • Database Level
        • Interface Level(Stored Proc, Views, Functions etc.)
        • Object Level(Table, Columns, Index etc.)
      • Type Of Documentation [Key]
        • Purpose
        • Process Mapping
        • Last Modified By(Not applicable for all objects)
    Use that data to prepare your presentaion.

.

How to Add Documentation / ExtendedProperties to SQL Objects

Keep below points in Mind

  1. Meaning of level0/level1/level2 in below commands
    1. The [level0] type is essentially the class of object. Valid Input: ASSEMBLY, CONTRACT, EVENT NOTIFICATION, FILEGROUP, MESSAGE TYPE, PARTITION FUNCTION , PARTITION SCHEME, REMOTE SERVICE BINDING, ROUTE, SCHEMA, SERVICE, USER, TRIGGER, TYPE, PLAN GUIDE, and NULL
    2. The [level1] is the object type that we usually work with. Valid Input: AGGREGATE, DEFAULT, FUNCTION, LOGICAL FILE NAME, PROCEDURE, QUEUE, RULE, SEQUENCE , SYNONYM, TABLE, TABLE_TYPE, TYPE, VIEW, XML SCHEMA COLLECTION, and NULL
    3. The [level2] is the dependent object. Valid Input : COLUMN, CONSTRAINT, EVENT NOTIFICATION, INDEX, PARAMETER, TRIGGER, and NULL
  2. Modify the Red Text in below Commands with appropriate Object Name in your Database

# Documentation Type SQL Object Action Syntax
1 Purpose Database Add
USE [master]
GO
EXEC [YourDatabasename].sys.sp_addextendedproperty @name=N'Purpose', @value=N'Provide Purpose' 
GO
                            
1 ProcessMapping Database Add
USE [master]
GO
EXEC [YourDatabasename].sys.sp_addextendedproperty @name=N'ProcessMapping', @value=N'Comma Seperated Processes' 
GO
                            
1 Purpose Database Update
USE [master]
GO
EXEC [YourDatabasename].sys.sp_updateextendedproperty @name=N'Purpose', @value=N'Updated Purpose' 
GO
                            
1 ProcessMapping Database Update
USE [master]
GO
EXEC [YourDatabasename].sys.sp_updateextendedproperty @name=N'ProcessMapping', @value=N'Comma Seperated Processes Added' 
GO
                            
1 Purpose Database Delete
USE [master]
GO
EXEC [YourDatabasename].sys.sp_dropextendedproperty @name=N'Purpose' 
GO
                            
1 ProcessMapping Database Delete
USE [master]
GO
EXEC [YourDatabasename].sys.sp_dropextendedproperty @name=N'ProcessMapping' 
GO
                            
1 Purpose Stored Procedures / Views / Functions Add
USE [YourDatabasename]
GO
EXEC sys.sp_addextendedproperty @name=N'Purpose', @value=N'Provide Purpose' 
                , @level0type=N'SCHEMA',@level0name=N'dbo'
                , @level1type=N'PROCEDURE/VIEW/FUNCTION',@level1name=N'Stored Procedure/Views/Functions Name'
GO
                            
1 ProcessMapping Stored Procedures / Views / Functions Add
USE [YourDatabasename]
GO
EXEC sys.sp_addextendedproperty @name=N'ProcessMapping', @value=N'Comma Septerated Process Mapping' 
                , @level0type=N'SCHEMA',@level0name=N'dbo'
                , @level1type=N'PROCEDURE/VIEW/FUNCTION',@level1name=N'Stored Procedure/Views/Functions Name'
GO
                            
1 Last Modified By Stored Procedures / Views / Functions Add
USE [YourDatabasename]
GO
EXEC sys.sp_addextendedproperty @name=N'LastModifiedBy', @value=N'Last Modified By Person' 
                , @level0type=N'SCHEMA',@level0name=N'dbo'
                , @level1type=N'PROCEDURE/VIEW/FUNCTION' ,@level1name=N'Stored Procedure/Views/Functions Name'
GO
                            
1 Purpose Stored Procedures / Views / Functions Update
USE [YourDatabasename]
GO
EXEC sys.sp_updateextendedproperty @name=N'Purpose', @value=N'Updated Purpose' 
                , @level0type=N'SCHEMA',@level0name=N'dbo'
                , @level1type=N'PROCEDURE/VIEW/FUNCTION',@level1name=N'Stored Procedure/Views/Functions Name'
GO
                            
1 ProcessMapping Stored Procedures / Views / Functions Update
USE [YourDatabasename]
GO
EXEC sys.sp_updateextendedproperty @name=N'ProcessMapping', @value=N'Updated Comma Septerated Process Mapping' 
                , @level0type=N'SCHEMA',@level0name=N'dbo'
                , @level1type=N'PROCEDURE/VIEW/FUNCTION',@level1name=N'Stored Procedure/Views/Functions Name'
GO
                            
1 Last Modified By Stored Procedures / Views / Functions Update
USE [YourDatabasename]
GO
EXEC sys.sp_updateextendedproperty @name=N'LastModifiedBy', @value=N'Last Modified By Person' 
                , @level0type=N'SCHEMA',@level0name=N'dbo'
                , @level1type=N'PROCEDURE/VIEW/FUNCTION',@level1name=N'Stored Procedure/Views/Functions Name'
GO
                            
1 Purpose Stored Procedures / Views / Functions Delete
USE [YourDatabasename]
GO
EXEC sys.sp_dropextendedproperty @name=N'Purpose' , @level0type=N'SCHEMA',@level0name=N'dbo'
                , @level1type=N'PROCEDURE/VIEW/FUNCTION',@level1name=N'Stored Procedure/Views/Functions Name'
GO
                            
1 ProcessMapping Stored Procedures / Views / Functions Delete
USE [YourDatabasename]
GO
EXEC sys.sp_dropextendedproperty @name=N'ProcessMapping' , @level0type=N'SCHEMA',@level0name=N'dbo'
                , @level1type=N'PROCEDURE/VIEW/FUNCTION',@level1name=N'Stored Procedure/Views/Functions Name'
GO
                            
1 Last Modified By Stored Procedures / Views / Functions Delete
USE [YourDatabasename]
GO
EXEC sys.sp_dropextendedproperty @name=N'LastModifiedBy' , @level0type=N'SCHEMA',@level0name=N'dbo'
                , @level1type=N'PROCEDURE/VIEW/FUNCTION',@level1name=N'Stored Procedure/Views/Functions Name'
GO
                            
1 Purpose Triggers Add
USE [YourDatabasename]
GO
EXEC sys.sp_addextendedproperty @name=N'Purpose', @value=N'Provide Purpose' 
                , @level0type=N'SCHEMA',@level0name=N'dbo'
                , @level1type=N'TABLE',@level1name=N'Table Name'
                , @level2type=N'TRIGGER',@level2name=N'TRIGGER Name'
GO
                            
1 ProcessMapping Triggers Add
USE [YourDatabasename]
GO
EXEC sys.sp_addextendedproperty @name=N'ProcessMapping', @value=N'Comma Septerated Process Mapping' 
                , @level0type=N'SCHEMA',@level0name=N'dbo'
                , @level1type=N'TABLE',@level1name=N'Table Name'
                , @level2type=N'TRIGGER',@level2name=N'TRIGGER Name'
GO
                            
1 Last Modified By Triggers Add
USE [YourDatabasename]
GO
EXEC sys.sp_addextendedproperty @name=N'LastModifiedBy', @value=N'Last Modified By Person' 
                , @level0type=N'SCHEMA',@level0name=N'dbo'
                , @level1type=N'TABLE',@level1name=N'Table Name'
                , @level2type=N'TRIGGER',@level2name=N'TRIGGER Name'
GO
                            
1 Purpose Triggers Update
USE [YourDatabasename]
GO
EXEC sys.sp_updateextendedproperty @name=N'Purpose', @value=N'Updated Purpose' 
                , @level0type=N'SCHEMA',@level0name=N'dbo'
                , @level1type=N'TABLE',@level1name=N'Table Name'
                , @level2type=N'TRIGGER',@level2name=N'TRIGGER Name'
GO
                            
1 ProcessMapping Triggers Update
USE [YourDatabasename]
GO
EXEC sys.sp_updateextendedproperty @name=N'ProcessMapping', @value=N'Updated Comma Septerated Process Mapping' 
                , @level0type=N'SCHEMA',@level0name=N'dbo'
                , @level1type=N'TABLE',@level1name=N'Table Name'
                , @level2type=N'TRIGGER',@level2name=N'TRIGGER Name'
GO
                            
1 Last Modified By Triggers Update
USE [YourDatabasename]
GO
EXEC sys.sp_updateextendedproperty @name=N'LastModifiedBy', @value=N'Last Modified By Person' 
                , @level0type=N'SCHEMA',@level0name=N'dbo'
                , @level1type=N'TABLE',@level1name=N'Table Name'
                , @level2type=N'TRIGGER',@level2name=N'TRIGGER Name'
GO
                            
1 Purpose Triggers Delete
USE [YourDatabasename]
GO
EXEC sys.sp_dropextendedproperty @name=N'Purpose' 
                , @level0type=N'SCHEMA',@level0name=N'dbo'
                , @level1type=N'TABLE',@level1name=N'Table Name'
                , @level2type=N'TRIGGER',@level2name=N'TRIGGER Name'
GO
                            
1 ProcessMapping Triggers Delete
USE [YourDatabasename]
GO
EXEC sys.sp_dropextendedproperty @name=N'ProcessMapping' 
                , @level0type=N'SCHEMA',@level0name=N'dbo'
                , @level1type=N'TABLE',@level1name=N'Table Name'
                , @level2type=N'TRIGGER',@level2name=N'TRIGGER Name'
GO
                            
1 Last Modified By Triggers Delete
USE [YourDatabasename]
GO
EXEC sys.sp_dropextendedproperty @name=N'LastModifiedBy' 
                , @level0type=N'SCHEMA',@level0name=N'dbo'
                , @level1type=N'TABLE',@level1name=N'Table Name'
                , @level2type=N'TRIGGER',@level2name=N'TRIGGER Name'
GO