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 |
IK1972
56 Posts |
Posted - 2014-06-06 : 19:37:46
|
Hi,I have one big database I want to check for all numeric data type columns I want to check what is min or max value in table. reason to check this is I want to confirm data type is correct like if for any bigint column I have max value 500 then it means datatype for this column is not correct so I will update later. for below query I just want to get Min and Max value for that column.select c.TABLE_CATALOG, c.TABLE_SCHEMA, c.TABLE_NAME, c.COLUMN_NAME, c.IS_NULLABLE, c.DATA_TYPEfrom INFORMATION_SCHEMA.COLUMNS cwhere c.DATA_TYPE in ('int', 'bigint','money','decimal','float','numeric','real','smallint','smallmoney','tinyint')and c.TABLE_SCHEMA not in ('dbo')order by c.TABLE_SCHEMA |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2014-06-06 : 20:10:37
|
Performance is going to suck for the large tables unless the columns are indexed.Copy/paste/execute:select 'select min(' + COLUMN_NAME + '), max(' + COLUMN_NAME + ') from ' + TABLE_SCHEMA + '.' + TABLE_NAMEfrom INFORMATION_SCHEMA.COLUMNSwhere DATA_TYPE in ('int', 'bigint','money','decimal','float','numeric','real','smallint','smallmoney','tinyint')order by TABLE_SCHEMATara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
|
|
|
|
|