Find columns with NULL values in Teradata

一笑奈何 提交于 2019-12-11 16:16:36

问题


I would like to find the columns in a table that has a null value in it. Is there a system table that have that information?


回答1:


To find columns where "null" values are allowed try...

select *
from dbc.columns 
where databasename = 'your_db_name'
and tablename = 'your_table_name'
and Nullable = 'Y'

then to identify the specific rows w/ null values, take the "ColumnName" from the previous result set and run queries to identify results... perhaps throw them in a volatile table if you want to take further action on them (update,delete).

-- for example you found out that column "foo" is nullable... 
create volatile table isnull_foo_col
as
(
  sel * 
  from your_table_name 
  where foo is null
) with data 
on commit preserve rows;



回答2:


If you have statistics collected on the column you can use the views found here for Teradata 12.0.03+ and Teradata 13.0.02+ to determine the number of records in the table that have NULL values.

In Teradata 14, if you use the SHOW STATISTICS with the VALUES clause you will get similar information generated by the views listed at the link above.

You can use the DBC.Columns data dictionary view to determine what columns in a particular table are nullable.



来源:https://stackoverflow.com/questions/16533202/find-columns-with-null-values-in-teradata

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!