SQL SERVER – Tracking Database Dependencies

In this blog post we will be learning about tracking database dependencies.

Dependency Analysis

If database changes are needed to be made at a column level, it’s essential that you perform impact assessment in order to determine which objects will be affected after the change. This means that SQL table column dependencies within a database need to be analyzed.

ApexSQL Clean is a tool that is used to analyze SQL server database dependencies and also to remove unwanted objects.

To analyze table column dependencies within a SQL database the first thing you need to do is to create a new project. That can be done by clicking the New button in the Home tab and choosing the desired server and the database.

SQL SERVER - Tracking Database Dependencies apextracking1

After that you need to select the Column dependencies button/option. Activating it will include all visible columns in the results grid and will make it expandable and be able to preview every column for each table.

SQL SERVER - Tracking Database Dependencies apextracking2

The column type is automatically shown alongside the column name, whether it’s ROWGUID, Identity type or a regular column.

SQL SERVER - Tracking Database Dependencies apextracking3

For any selected column or object, ApexSQL Clean provides additional information in both Children and Parents panes. The Parents pane contains a list of database objects, that the selected object depends on.

SQL SERVER - Tracking Database Dependencies apextracking4

Solarwinds

Every time a table schema is modified, it is very important to detect all possible SQL database objects that might be affected after the change. ApexSQL Clean has a main advantage which is that it leverages dependency analysis algorithms to display column level dependencies, not like in SSMS, where the object level dependencies can only be viewed. Without performing a full analysis, there is a possible risk of causing problems after implementing the update.

Graphical representation of dependencies

The Dependency viewer allows the visualization of all SQL object dependencies, including relationships that affect encrypted objects, system objects, or objects stored in databases encrypted with Transparent Data Encryption (TDE).

SQL SERVER - Tracking Database Dependencies apextracking5

The Dependency viewer shows database object dependencies relative to each other in an easy to understand, well organized visual format, and offers various options for object manipulation, appearance, filtering, and more.

SQL SERVER - Tracking Database Dependencies apextracking6

Visual dependencies can be displayed in four available types:

  • Circular
  • Hierarchical
  • Force directed
  • Orthogonal

Visual dependencies can be filtered out by using four dependency filters:

  • Children only – Using this filter shows the specified object and the objects that directly depend on it
  • Descendants – Shows the specified object, all objects that depend on it and all the objects that depend on those objects as well
  • Parents and children only – This filter shows the specified object, all of the objects it depends on and the objects that directly depend on it
  • Parents and descendants only – Shows the whole dependency chain (the selected object, all of the objects it depends on, all objects that depend on it and all of the objects that depend on those objects as well)

The dependency viewer feature, besides the previously mentioned ability to display the database dependencies graphically, also offers the choice of customizing and designing the overall appearance of the dependency diagrams. This option is used to improve the visual look and readability of dependency diagrams. Those customization capabilities are:

  • Layout editing – resizing nodes and clusters, moving nodes and edges
  • Format functionality – adjusting colors, shapes and fonts for all graphical objects
  • Creation of custom graphs – manual definition of object position and size
  • General navigation – zooming and scrolling

Analyzing dependencies in client code

Among all other features ApexSQL Clean is packed with a very useful feature that unfortunately most people are not even aware of. This feature manages SQL code analysis in Delphi, C#, XML, XAML, VB.NET, ASP.NET, CSS, HTML code etc., and detects what SQL objects are actually used and which ones aren’t. This helpful little feature keeps SQL databases stay clean and well organized.

Remove unwanted objects

In order to find any unreferenced objects that should be removed from a SQL database create a new project, select a database and click OK. Once that is done, the objects referential status will be displayed in the results grid. All unreferenced SQL objects will be marked with a green checkmark in the Unreferenced column. Only these objects can be selected to be removed from the database.

SQL SERVER - Tracking Database Dependencies apextracking7

To clean up the database, select those objects and click the Create drop script button in the Actions tab.

SQL SERVER - Tracking Database Dependencies apextracking8

After that, the drop script generation menu will appear, where you can select the SQL objects to be cleaned up. Selected objects are automatically checked before running the drop script generation menu.

SQL SERVER - Tracking Database Dependencies apextracking9

The next step offers the choice to create a drop script which can be used later, or to execute the created script and remove all unwanted objects. If you choose the Create drop script option, you can save it in a desired location or open the script in either ApexSQL built-in editor or in some other external editors, like SSMS, Notepad++ etc.

SQL SERVER - Tracking Database Dependencies apextracking10

After executing the drop script an additional message dialog will appear with the script execution results.

Creating a database cleanup report

Creating a report is easy to do and you will be provided with detailed information after, whether you want to include parent-children objects, or maybe you need to generate a document which contains objects that have no children objects or any other references. To create a cleanup report of unreferenced objects, click the Export button in the Actions tab.

SQL SERVER - Tracking Database Dependencies apextracking11

As shown above, there are two types of export options available. HTML and XML report. Selecting either option will result in opening a new menu with additional customization options shown below:

SQL SERVER - Tracking Database Dependencies apextracking12

Select the needed report options and click OK. The generated cleanup report will contain previously selected information and it will allow the printing of a copy if it is necessary. A sample of a created HTML report can be seen below:

SQL SERVER - Tracking Database Dependencies apextracking13

On the other hand, if you decide to create an XML report, the exported file will be created in .XML format and will look similar to this:

SQL SERVER - Tracking Database Dependencies apextracking14

With the create report feature, ApexSQL Clean will create a well-organized document which contains all information about objects and their dependencies. Whether they are needed for reporting referenced objects, or maybe to keep a record of the unreferenced ones.

Reference: Pinal Dave (https://blog.sqlauthority.com)

Solarwinds
, ,
Previous Post
SQL SERVER – Database Auditing and Compliance
Next Post
SQL SERVER – Delayed Durability, or The Story of How to Speed Up Autotests From 11 to 2.5 Minutes

Related Posts

Leave a Reply

Menu