I am working on a bunch of very complicated stored procedures on SQLSERVER 2012 Express databases using SQLSEVER 2012 Management studio.
For example I have a stored procedure SP1 calling another stored procedure SP2 and SP2 calls SP3, SP3 calls SP4 ...
What I would like to see is a diagram that can provide me the full relationships between these stored procedures and all the tables that being used in these stored procedures.
I have tried the view dependencies tools provided by SQL Server management studio, but sometimes it misses descendants stored procedures when I click "View Dependencies" of a selected stored procedure. Also it can't show a full picture of relationships between these stored procedures.
Is there any tool can help me with this? Or any suggestions on how to understand complicated relationship stored procedures?
Open the Table Designer for the table containing the foreign key you want to view, right-click in the Table Designer, and choose Relationships from the shortcut menu. In the Foreign Key Relationships dialog box, select the relationship with properties you want to view.
From Stored Procedure Properties, select the Permissions page. To grant permissions to a user, database role, or application role, select Search. In Select Users or Roles, select Object Types to add or clear the users and roles you want. Select Browse to display the list of users or roles.
Using SQL Server Management StudioExpand Stored Procedures, right-click the procedure and then select Script Stored Procedure as, and then select one of the following: Create To, Alter To, or Drop and Create To. Select New Query Editor Window. This will display the procedure definition.
When you need to establish a many-to-many relationship between two or more tables, the simplest way is to use a Junction Table. A Junction table in a database, also referred to as a Bridge table or Associative Table, bridges the tables together by referencing the primary keys of each data table.
I found following query quite useful, hope it can help.
select
distinct
ObjJectType=
case Obj.xType
When 'V' then
'VIEW'
When 'P' then
'PROC'
When 'D' then
'INDEX'
When 'TF' then
'TABLE FUNCTION'
When 'FN' then
'FUNCTION'
When 'U' then
'TABLE'
When 'F' then
'FK CONSTRAINT'
When 'PK' then
'PK CONSTRAINT'
When 'TR' then
'TRIGGER'
When 'S' then
'SYSTEM OBJECT'
end ,
Obj.name
from
syscomments Com inner join sysobjects Obj
on Com.id = Obj.id
where
Com.text like '%sp_name%'
order by Obj.name
You can build a recursive query around sys.objects joined on sys.sql_modules (the definition field contains the sproc code) and build yourself a dependencies tree.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With