0
I made a select using metadata, but the result of my selection brought me something like 'Cross Join'. Even using GROUP BY and DISTINCT returns with duplicate values. I would like an help to return the values correctly ... follows sql:
SQL:
SELECT distinct
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)
TEP.value as 'Descrição'
FROM sys.columns C
INNER JOIN sys.tables T
ON T.object_id = C.object_id
LEFT JOIN sys.schemas S
ON T.schema_id = S.schema_id
INNER JOIN sys.types TY
ON TY.user_type_id = C.user_type_id
LEFT JOIN sys.extended_properties TEP
ON T.object_id = TEP.major_id
Result image:
I think the problem is from the last JOIN, when I change the parameter 'TEP.major_id' to 'TEP.minor_id' it returns the correct values, but without the descriptions of the columns.
Not duplicated because the values in the last column are different. One of the ways to solve this is by making a select of this select by filtering only what you want. SELECT * FROM ( seu_select ) A WHERE DESCRIPTION = 'o_que_desejar'
– Reginaldo Rigo