Click here to Skip to main content
15,905,323 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi ,
I want to khow the how to get the Size of table column from sys object method in sql server 2005.
i got table Column name with sys.column , DataType with sys.types, then i want to khow how we got Column Size ?
I want to run below quary.

SQL
Select 1 from sys.objects A, sys.columns B , sys.types C Where A.object_id = B.object_id And  A.name = 'tbl_13' And B.name='name' And C.name ='varchar'


Thanks in advanced.
regards
Ravi
Posted
Updated 14-Sep-11 20:57pm
v2

1 solution

To measure the length of VARCHAR fields you can use the function
LEN(varcharfield) .

To measure the length of TEXT fields the function is DATALENGTH(textfield). Len will not work for text field.

Example:
SQL
SELECT DATALENGTH(yourtextfield) AS TEXTFieldSize


Markus
 
Share this answer
 
v4
Comments
Ravi Sharma 2 15-Sep-11 3:09am    
How to find out the length with Sys object
MZwahlen 15-Sep-11 3:38am    
Try 'select *' instead of 'select 1'

You can get all information about a TableRow with:

Select * from sys.objects A, sys.columns B , sys.types C Where A.object_id = B.object_id And A.name = 'tbl_13' And B.name='name' And C.name ='varchar'

the length is in 'max_length'

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900