I am trying to access the Column description properties using the INFORMATION_SCHEMA
I have created this Query in the past to get the column name but i can not figure out how to get description of the column
SELECT COLUMN_NAME AS Output, ORDINAL_POSITION
FROM INFORMATION_SCHEMA.COLUMNS
WHERE (TABLE_NAME = @Tablename) AND (ORDINAL_POSITION = @Location)
This is where the Description is on the field properties
SQL DESCRIBE TABLE is a SQL statement that is accountable for telling something about a specific table in the database. If we want to show the structure of a database table or tables in the server then, we will use the SQL command DESCRIBE or other keyword DESC, which is identical to DESCRIBE one.
The DESC command is used to sort the data returned in descending order.
If by 'description' you mean 'Description' displayed in SQL Management Studio in design mode, here it is:
select
st.name [Table],
sc.name [Column],
sep.value [Description]
from sys.tables st
inner join sys.columns sc on st.object_id = sc.object_id
left join sys.extended_properties sep on st.object_id = sep.major_id
and sc.column_id = sep.minor_id
and sep.name = 'MS_Description'
where st.name = @TableName
and sc.name = @ColumnName
If you specifically want to use INFORMATION_SCHEMA (as I was) then the following query should help you obtain the column's description field:
SELECT COLUMN_NAME AS [Output]
,ORDINAL_POSITION
,prop.value AS [COLUMN_DESCRIPTION]
FROM INFORMATION_SCHEMA.TABLES AS tbl
INNER JOIN INFORMATION_SCHEMA.COLUMNS AS col ON col.TABLE_NAME = tbl.TABLE_NAME
INNER JOIN sys.columns AS sc ON sc.object_id = object_id(tbl.table_schema + '.' + tbl.table_name)
AND sc.NAME = col.COLUMN_NAME
LEFT JOIN sys.extended_properties prop ON prop.major_id = sc.object_id
AND prop.minor_id = sc.column_id
AND prop.NAME = 'MS_Description'
WHERE tbl.TABLE_NAME = @TableName
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With