Skip to content

Produce a GraphViz file

MichaelSScott edited this page Nov 13, 2019 · 3 revisions

Once you have created a dependency table you pass it to a GraphDoc procedure to generate output in the format required by the GraphViz dot command to render a diagram.

For example, in SSMS on the AdventureWorks2017 database run

DECLARE @dep [GraphDoc].[udtt_DependencyGraph]

Insert into @dep
Select distinct * from [GraphDoc].[udf_cs_DepTable] ('dbo', 'uspGetBillOfMaterials')

SET NOCOUNT ON
DECLARE @RC int

EXECUTE @RC = [GraphDoc].[usp_cs_DrawDependencyGraph] 
   @dep
  ,@FriendlyName  = 'Get Bill of Materials'
  ,@direction = 'LR'  
  ,@overview='Y'
  ,@description='AdventureWorks Example'
GO

The GraphDoc.usp_cs_DrawDependencyGraph procedure takes a number of arguments. The ones shown above are those you are most likely to use. Here's the full list;

CREATE PROCEDURE [GraphDoc].[usp_cs_DrawDependencyGraph]
	@dep udtt_DependencyGraph READONLY,
	@FriendlyName nvarchar(255) = NULL,
	@collapse_nonlocal_db char(1) = 'N', -- Y/N, default N
	@direction char(2) = 'TB',  -- LR, BT, RL. top to bottom, left to right, etc.
	@graphsection tinyint = 1, -- 1 = all, 2 = notail, 4 = body, 8 = nohead
	@overview char(1) = 'N', -- Y = ensure table/view objects are in the namespace of the base object.
	@description nvarchar(max) = NULL,
	@codesample nvarchar(max) = NULL
  • @dep is the dependency table from the earlier step. It has to be there of course.
  • @FriendlyName is optional. If blank then the procedure will just display 'GraphDoc' in its place.
  • @Direction tells dot about the placement of nodes. For procedures I think it looks better left-to-right, and for Jobs top-to-bottom , but try it out.
  • @Overview can be Y, N or H. Y will only show the top level procedure (i.e., the one you specified in the previous step). N will show much the same but without any framing. It's really used by the job graphing procedure and probably not so useful for procedures. H shows the complete call hierarchy from the top level down.
  • @collapse_nonlocal_db if set to Y will not display the objects used on databases other than the one in which we are running. This is here because I had some remote databases with procedures that used ridiculous numbers of tables and the resulting diagram was way too big to be useful.
  • @Description will be displayed top and bottom of the diagram. The remaining parameters are used by the job graphing procedure.

Clone this wiki locally