Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Gathering Database table information?
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic
Yak Posting Veteran

77 Posts

Posted - 03/14/2013 :  00:30:48  Show Profile  Reply with Quote
I am trying to find below information from the table in tabular format . I can getRows Count, Column Name and Attribute (DataType)

Database Name,
Table Name,
No.Of columns,
No.Of Rows Count,
Column name,
Attribute (DataType),
Min Value,
Max Value,
Non null count,
Distinct count of the column


Database Name | Table Name | No.Of columns | No.Of Rows Count | Column name  | Attribute (DataType)| Min Value | Max Value | Non null count | Distinct count of the column

SWISS_WIP | tbl_Files | 5 | 150 | Prod_Beg | int | 25 | 123212 | 123100 | 10
SWISS_WIP | tbl_Files | 5 | 150 | File_MD5| varchar | null | null | 12232| null

How can we do this?

Flowing Fount of Yak Knowledge

2242 Posts

Posted - 03/14/2013 :  02:55:22  Show Profile  Reply with Quote
From INFORMATION_SCHEMA.columns we can get following information:

Database Name,
Table Name,
No.Of columns,
Column name,
Attribute (DataType),
Max Length,
Non null count

SELECT Table_CATALOG DBName, Table_Name, MAX(Ordinal_position) OVER(Partition by Table_name) NoOfColumns, Column_name,
Data_Type, Coalesce(CHARACTER_MAXIMUM_LENGTH, Numeric_precision, datetime_Precision) MaxLength,
SUM( CASE WHEN IS_NULLABLE = 'NO' THEN 1 END) OVER(Partition by Table_name) NonNullCount

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000