sql server 2005 - Find fields that aren't used (have all nulls) -


I inherited a legacy database, and many, many fields are not being used anymore I can inquire and see which fields are zero, find at least one baseline where I can see.

What is a great way to find out which fields in the database are empty for all records in a set?

  announcement @table NVARAR (512); SET @table = N'dbo.tablename '; DECLARE @sql NVARCHAR (max); SELECT @sql = N ''; SELECT @sql = @sql + QUOTENAME (name) + '= SUM (case when' + QUOTENAME (name) + 'then 1 ELSE 0 is end),' WHERE object_ID from OOZETEDID (TTB) and ' Is_a = 1; SELECT @sql = 'SELECT' + @sql + 'Total_Count = COUNT (*) FROM' + @table + ';'; EXEC sp_executesql @sql;   

Any column that comes out of 0 has all the nulls (unless the total column is also out of 0, the table is empty). Note that this query will be quite expensive on the large query.

Comments