SQL Server 2017 - Recover column description/comment in table in database - Metadata

Asked

Viewed 422 times

0

I am trying to generate a data dictionary of my database in SQL Server 2017, and would like to recover the description/comment of the 'Description' field contained in the column definitions of each table. I was inspired by a code I found on a site, but I’m not able to add this table metadata.

Desired field:

Campo description

SQL I am using:

SELECT

S.name as 'Schema',

T.name as Tabela,

C.name as Coluna,

TY.name as Tipo,

C.max_length as 'Tamanho Máximo', -- Tamanho em bytes, para nvarchar normalmente se divide este valor por 2

C.precision as 'Precisão', -- Para tipos numeric e decimal (tamanho)

C.scale as 'Escala' -- Para tipos numeric e decimal (números após a virgula)

FROM sys.columns C

INNER JOIN sys.tables T
ON T.object_id = C.object_id

INNER JOIN sys.types TY
ON TY.user_type_id = C.user_type_id

LEFT JOIN sys.schemas S
ON T.schema_id = S.schema_id

1 answer

0


The Description column is in the table sys.extended_properties, need to include in your select making Join with object_id, like this:

left join sys.extended_properties tep on T.object_id = tep.major_id 

I used left join if the column has not Description. Include in select the column "value":

tep.value [Description]
  • It worked!!! Thank you very much man, you are beast !!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.