Checking SQL code for unused column references?

  • I have a couple long (1000+ lines) queries in development. I tend to use a lot of CTEs, and throw in columns that seem helpful at the time, but may not be used in the final query.

    Does anyone know a tool that will scan a query and list columns that have been included in a CTE but are not used later in the query?  Kind of like how Visual Studio will complain if you declare a variable but don't use it.

    I've looked at SSMS and Aqua Data for something like this, but haven't found it.

    Thanks,

  • Hi,
    I think that you should read the article in the link, apply to Oracle, but SQL Server too.
    https://stackoverflow.com/questions/25186267/managing-very-large-sql-queries
    Good Luck

  • palandri - Thursday, October 19, 2017 12:33 PM

    I have a couple long (1000+ lines) queries in development. I tend to use a lot of CTEs, and throw in columns that seem helpful at the time, but may not be used in the final query.

    Does anyone know a tool that will scan a query and list columns that have been included in a CTE but are not used later in the query?  Kind of like how Visual Studio will complain if you declare a variable but don't use it.

    I've looked at SSMS and Aqua Data for something like this, but haven't found it.

    Thanks,

    If a column is included in a CTE but not used in the final query, it will be ignored. Unless, it's used as part of a filtering or grouping option.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply