Skip to content

Instantly share code, notes, and snippets.

@tech-andgar
Created November 21, 2017 12:56
Show Gist options
  • Save tech-andgar/15207590ea3a7f00fd990723691fa362 to your computer and use it in GitHub Desktop.
Save tech-andgar/15207590ea3a7f00fd990723691fa362 to your computer and use it in GitHub Desktop.
SQL Server - Cómo generar Diccionario de Datos en SQL Server 2008 - 2017 (Link Original: https://www.lawebdelprogramador.com/foros/SQL-Server/1590219-Como-generar-Diccionario-de-Datos-en-SQL-Server-2008.html)
select a.name [ENTIDAD],
b.name [CAMPOS],
c.name + '(' + CAST(c.length AS VARCHAR) + ')' AS [TIPO DE DATO],
case when b.isnullable=0 then 'NO' else 'SI' end [NULL],
case when d.name is null then '' else 'X' end [PK],
case when e.parent_object_id is null then '' else 'X' end [FK],
case when h.value is null then '' else h.value end [DESCRIPCIÓN]
from sysobjects as a
join syscolumns as b
on a.id = b.id
join systypes as c
on b.xtype = c.xtype
left join (SELECT so.id,
sc.colid,
sc.name
FROM syscolumns sc
join sysobjects so
on so.id = sc.id
join sysindexkeys si
on so.id = si.id and
sc.colid = si.colid
WHERE si.indid = 1) d
on a.id = d.id and
b.colid = d.colid
left join sys.foreign_key_columns as e
on a.id = e.parent_object_id and
b.colid = e.parent_column_id
left join sys.extended_properties as h
on a.id = h.major_id and
b.colid = h.minor_id
where a.type = 'U'
order by a.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment