Skip to content
Ashton MacKenzie

Ashton MacKenzie

There is nothing old under the sun.

  • About / Work With Me
    • Shared Treats
  • Portfolio
    • Discogs Utility
    • The Guild of the Magi – Everything
      • The Guild of the Magi Demo
      • The Guild of the Magi – Pre Alpha
    • Zines
  • Reference Library
    • Reference Notes
    • Deploying a React Ruby app on Fly.io if you’ve never deployed a thing in your life
    • Introduction to Networks for Software Engineers
      • Handling Requests That Update Multiple Models in Ruby on Rails
      • DNS
      • Layer 1 – Media
      • Layer 2 – Link Layer (Part One)
    • Privacy Policy
  • Latest Posts
  • Friends
  • Home
  • 2023
  • November
  • 6
  • Forensic Maintenance in SQL Server
Reference Technology

Forensic Maintenance in SQL Server

November 6, 2023April 21, 2025 A MacKenzie

Querying Metadata – it’s like a dinosaur dig

Lately I have been doing some work on a tool that connects to an outside service. This tool does not have any documentation, nor does there appear to be any live humans with institutional knowledge. How is a developer supposed to gain insight into a tool like that?

Most database engines allow for users with the privilege to do so to query the system tables for information about the relationship between different database tools.

The way I approached this issue was starting from the field level.

First, the backstory: The ask came in from a user, who described a particular change that needed to be made to a certain piece of data. Helpfully, this piece of data is relatively unique in the database. Between referencing the form itself that the user would interface with and an out-of-date data dictionary, I was able to determine what the field that contains this data is called. In our example, we’ll call this field ‘crypticallyNamedField’.

Now, it is possible to query a database’s system for information about items that use a field. I like this answer by AdaTheDev on StackOverflow for its brevity:

SELECT      COLUMN_NAME AS'ColumnName'
            ,TABLE_NAME AS'TableName'FROM        INFORMATION_SCHEMA.COLUMNS
WHERE       COLUMN_NAME LIKE'%MyName%'ORDERBY    TableName
            ,ColumnName;

To suit our purposes we only need to change one thing:

SELECT      COLUMN_NAME AS'ColumnName'
            ,TABLE_NAME AS'TableName'FROM        INFORMATION_SCHEMA.COLUMNS
WHERE       COLUMN_NAME LIKE'%crypticallyNamedField%'ORDERBY    TableName
            ,ColumnName;

This will gather us a list of list of not just tables, but views, that contain a field with the name that we’re looking for.

In my case, I only got two tables back, likelyTable, and tableNoOneHasEverHeardOf.

I can gain insight into which table I think is more likely the one that the tool is using by looking at what depends on this table. If there are any stored procedures or reports that this tool uses, then they should come up in a query for what references this table. Use a query like this one by bjnr.

SELECT
        referencing_schema_name, referencing_entity_name, 
        referencing_class_desc, is_caller_dependent
FROM sys.dm_sql_referencing_entities ('<TableName>', 'OBJECT')

And note that again we only need to change one thing:

SELECT
        referencing_schema_name, referencing_entity_name, 
        referencing_class_desc, is_caller_dependent
FROM sys.dm_sql_referencing_entities ('<likelyTable>', 'OBJECT')

I got a few reports, and here we come to some Life Professional Skills. As a junior developer, it’s unlikely that you’re working in a complex legacy environment purely by yourself. This is a great amount of legwork to do to work with the data services or database administration team to identify what else your tool references.

In this case, I was able to provide the list of reports, with likely candidates for what the tool uses highlighted, to a senior developer and a database administrator. We explained the situation to the database admin and said that we weren’t quite sure what we were looking for, but we knew where the data was coming from, and had a close idea for where the data was going. The database administrator was able to use our clues to identify an SSIS package that references stored procedures and exports data that matches what the user describes. This saves time over trying to learn advanced database administration as well as gain institutional knowledge from crumbs.

References:

  • Find all tables containing column – AdaTheDev
  • Find all entities that refer to a given entity – bjnr
  • Photo

Thank you for reading. Please let me know if there are any clarifications I can make or further questions I can answer either down in the comments, on LinkedIn, or hit me up on Mastodon.

database, database administration, metadata, reference, sql server, technology, troubleshooting

Related Posts

Technology

You already use database normalization concepts to avoid food poisoning.

September 27, 2024April 21, 2025 A MacKenzie
Reference Technology

Practicing SQL in leetcode – Game Play Analysis

November 27, 2023April 21, 2025 A MacKenzie

Post navigation

Previous: Want to hear something about query languages that will make you actually appreciate callback functions and promises in programming languages?
Next: Practicing SQL in leetcode – Game Play Analysis

Recent Posts

  • 🥔✨Samosa Cottage Pie✨🥔
  • Mochiko Pão de Queijo
  • Manoomin Kitchari
  • March Zine – Vermont is my Home
  • February Zine – Food Exchange Group

Categories

  • Art
  • Blog
  • Crafts
  • español
  • Food
  • Mac
  • Natural Materials
  • Portfolio
  • Reference
  • Technology
  • Upcycling
  • zine

Archives

  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • September 2024
  • November 2023
  • October 2023
  • August 2023
  • July 2023
  • June 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Connect with me!

  • LinkedIn
  • Mastodon
  • GitHub

All Rights Reserved 2024.
Proudly powered by WordPress | Theme: Fairy by Candid Themes.