Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
zudnic
Starting Member
3 Posts |
Posted - 2015-02-05 : 17:55:04
|
I have an application that has grown organically, and people have asked for new fields and they have been added willy-nilly over time. I want to clean it up and find columns where every row is null - basically unused ones I can remove.This table is out of control, there are hundreds of columns, so doing this manually is not feasible.Is there a way to do this?Thank you! |
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2015-02-05 : 19:01:12
|
1) You could generate some dynamic SQL that would test each column.2) You could select the count of each column by name; since the null entries don't get included, any column that has a count of zero is unuseddeclare @T table ( col1 int null, col2 char null, colMT date null );insert into @tvalues (1, 'A', null), (null, 'B', null), (null, 'C', null), (4, null, null), (5, 'E', null)select count(col1), count(col2), count(colMT)from @T Those who will not reason, are bigots, those who cannot, are fools, and those who dare not, are slaves. -Lord Byron, poet (1788-1824) |
|
|
zudnic
Starting Member
3 Posts |
Posted - 2015-02-06 : 10:26:13
|
quote: Originally posted by Bustaz Kool 1) You could generate some dynamic SQL that would test each column.2) You could select the count of each column by name; since the null entries don't get included, any column that has a count of zero is unuseddeclare @T table ( col1 int null, col2 char null, colMT date null );insert into @tvalues (1, 'A', null), (null, 'B', null), (null, 'C', null), (4, null, null), (5, 'E', null)select count(col1), count(col2), count(colMT)from @T Those who will not reason, are bigots, those who cannot, are fools, and those who dare not, are slaves. -Lord Byron, poet (1788-1824)
Thank you! I'll give it a shot. |
|
|
jjourneyy22
Starting Member
3 Posts |
Posted - 2015-02-09 : 01:54:05
|
unspammed |
|
|
jackv
Master Smack Fu Yak Hacker
2179 Posts |
|
zudnic
Starting Member
3 Posts |
|
jackv
Master Smack Fu Yak Hacker
2179 Posts |
|
|
|
|
|
|