Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
exec sp_help 'tablename'

give whole table information but i want only Column_name ,datatype and Length of table

How can i get it ?
Posted
Comments
Aarti Meswania 14-Mar-13 8:45am    
length of table?
[no name] 14-Mar-13 8:50am    
length of datatype means varchar(50) than length = 50

Hi
Check this...
SQL
SELECT ORDINAL_POSITION , Column_Name,
	CASE WHEN Data_Type = 'Numeric' THEN Data_type + '('+CONVERT(VARCHAR,Numeric_Precision)+','+CONVERT(VARCHAR,Numeric_Scale) +')'
	WHEN Data_Type = 'Varchar' OR  Data_Type = 'Char' THEN Data_type + '('+CONVERT(VARCHAR,Character_Maximum_Length)+')'
	ELSE Data_type END 'Data Type',
	CASE WHEN IS_Nullable = 'NO' THEN 'NN' ELSE 'N' END 'NUll/NOT NULL'
FROM Information_Schema.Columns
WHERE table_name = 'Table_Name' 
ORDER BY TABLE_NAME , ORDINAL_POSITION 
 
Share this answer
 
Comments
[no name] 14-Mar-13 8:52am    
I got it :-)

but i also want length of datatype

and primary key if possible
gvprabu 14-Mar-13 8:54am    
Hi Length also there na...
gvprabu 14-Mar-13 8:55am    
Length will come only CHAR,VARCHAR ect..
that also like --> Test VARCHAR(10)
[no name] 14-Mar-13 8:56am    
VARCHAR(10) it work but is possible to add one more Column which contain length

like if varchar(50) than length = 50
gvprabu 14-Mar-13 8:58am    
Add this ... character_maximum_length
Try This One

SQL
SELECT column_name 'Column Name',
data_type 'Data Type',
character_maximum_length 'Maximum Length'
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'Country'
 
Share this answer
 
Comments
[no name] 14-Mar-13 9:04am    
yes it work thank you
any idea about for store procedure..?
Sumit_Kumar_Sinha 14-Mar-13 9:11am    
i m not getting
[no name] 14-Mar-13 9:26am    
possible same type of think for store procedure..?

means data about sp 'title' 'input' and 'output' parame..
sp_help returns all results.
You can always put the results in a temporary table and then write a view for only those items you require.
 
Share this answer
 

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