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'