SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

getur.srikanth@gmail.com
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)
quote:

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


Example:

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?

bandi
Flowing Fount of Yak Knowledge

India
2210 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
FROM INFORMATION_SCHEMA.columns

--
Chandu
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.05 seconds. Powered By: Snitz Forums 2000