最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

t sql - tsql to find the columns in tables that have never been used using data management views - Stack Overflow

programmeradmin4浏览0评论

I want to find all of the columns in a database that have never been used. By that I mean that for numeric column types, they coalesce to zero and for string column types they coalesce to a zero length string.

I easily created a query that gives me every column name in every table using the data management views. I also easily created a query, that given a table name and a column name gives me a count of discrete values found in that column.

What I want to do is cross apply those two queries so that I get one result set with the table name, column name and count of distinct values. I could then filter that to just the columns that have 1 or two distinct values and have the list that I want.

The issue is how to get the to merge the table and column names from the results of the first query into the second query. Dynamic sql works but I can not put it inside of a table valued function that I could cross join to get my desired result set because dynamic sql would make the function non-deterministic if it were allowed.

Does anyone have a method to accomplish this task?

发布评论

评论列表(0)

  1. 暂无评论