How to get column details (column, datatype) of table in SQL Server?

9.3k Views Asked by At

enter image description here

I am new to databases, I just created a table using "New Table", but I want to list of columns and their properties as shown in the screenshot.

What is the SQL command for this? I googled it before coming here but it's of no use, any help is appreciated. Thanks

2

There are 2 best solutions below

0
On

You Can Use This Query:

    SELECT * from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='YourTableName'

and this link may be helpful. visit https://learn.microsoft.com/en-us/sql/relational-databases/system-information-schema-views/columns-transact-sql?view=sql-server-ver15

0
On

You can use this Query

SELECT TAB.name AS TableName, COL.name AS ColumnName, TYP.name AS DataTypeName, 
TYP.max_length AS MaxLength
From sys.columns COL
INNER JOIN sys.tables TAB
On COL.object_id = TAB.object_id
INNER JOIN sys.types TYP
ON TYP.user_type_id = COL.user_type_id