Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Obtaining information about table using System views Expand / Collapse
Author
Message
Posted Monday, December 8, 2008 2:11 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, May 8, 2012 12:49 PM
Points: 339, Visits: 560
Hi there,
I am trying to retreive Column information from the DB. I am interested in getting Column name,its datatype and length of the column.
Using system views, I am getting column name and its datatype but is working with obtaining length of the column.
Does anyone know thru which system view, I can get that.
Thanks
Post #615782
Posted Monday, December 8, 2008 2:23 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, August 29, 2014 10:24 AM
Points: 1,867, Visits: 2,020
It depends on what datatype the column is and which "system views" you are using.

The easiest one to use is information_schema.columns
it has character_maximum_length column for CHAR, NCHAR, VARCHAR, NVARCHAR columns, and numeric_precision, numeric_scale for DECIMAL, NUMBER columns.

Simmilarly, in sys.columns, there is max_length for CHAR and VARCHAR, but you need to divide by 2 for NCHAR and NVARCHAR since they take 2 bytes per character. For DECIMAL and NUMBER use the precision and scale columns.
Post #615789
Posted Monday, December 8, 2008 2:37 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, May 8, 2012 12:49 PM
Points: 339, Visits: 560
Thanks!
I figured out.. :)
Post #615802
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse