Dot Net Stuff

Get Table information (Column Name, Data Type, Size) in SQL Server


A lot of beginner developer are facing this issue in IT industry, that how to Get Table information like Column Name, Data Type, Character length, Default Values etc in SQL Server.

Get Table information like Column Name, Data Type, Character length, Default Values etc in SQL Server.

To get the Table in information in SQL Server, we can use below Query:

SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'YourTableName'
ORDER BY ORDINAL_POSITION

how can we get fields name of a table with theirs type and size ?

Above query will provide you all the schema information. If you want to get only few data like fields name of a table with theirs type and size, than you can modify query like given below.

SELECT column_name as 'Column Name', data_type as 'Data Type',
character_maximum_length as 'Max Length'
FROM information_schema.columns
WHERE table_name = 'YourTableName' 

Keen to hear from you...!

If you have any questions related to what's mentioned in the article or need help with any issue, ask it, I would love to here from you. Please MakeUseOf Contact and i will be more than happy to help.

About the author

Anil Sharma is Chief Editor of dotnet-stuff.com. He's a software professional and loves to work with Microsoft .Net. He's usually writes articles about .Net related technologies and here to shares his experiences, personal notes, Tutorials, Examples, Problems & Solutions, Code Snippets, Reference Manual and Resources with C#, Asp.Net, Linq , Ajax, MVC, Entity Framework, WCF, SQL Server, jQuery, Visual Studio and much more...!!!

Comments are closed