MS SQL SERVER: Generar diccionario de datos
Generar diccionario de datos para MS SqlServer.
Consulta para generar diccionario de datos para MS SqlServer.
select
d.object_id,
a.name as [Tabla],
--schema_name(a.schema_id) schema_name,
--a.create_date,
b.name as [Columna],
c.name as [Tipo de dato],
CASE
WHEN c.name = 'numeric' OR c.name = 'decimal' OR c.name = 'float' THEN b.precision
ELSE null
END as [Precisión],
b.max_length as [Longitud],
CASE
WHEN b.is_nullable = 0 THEN 'No'
ELSE 'Si'
END as [Permite null],
CASE
WHEN b.is_identity = 0 THEN 'No'
ELSE 'Si'
END as [Es autonumérico],
ep.value as [Descripción],
f.ForeignKey as [Llave foranea (FK)],
f.ReferenceTableName as [FK: Tabla],
f.ReferenceColumnName as [FK: Columna]
from sys.tables a
inner join sys.columns b on a.object_id= b.object_id
inner join sys.systypes c on b.system_type_id= c.xtype
inner join sys.objects d on a.object_id= d.object_id
LEFT JOIN sys.extended_properties ep ON d.object_id = ep.major_id AND b.column_Id = ep.minor_id
LEFT JOIN (SELECT
f.name AS ForeignKey,
OBJECT_NAME(f.parent_object_id) AS TableName,
COL_NAME(fc.parent_object_id,fc.parent_column_id) AS ColumnName,
OBJECT_NAME (f.referenced_object_id) AS ReferenceTableName,
COL_NAME(fc.referenced_object_id,fc.referenced_column_id) AS ReferenceColumnName
FROM sys.foreign_keys AS f
INNER JOIN sys.foreign_key_columns AS fc ON f.OBJECT_ID = fc.constraint_object_id) f ON f.TableName =a.name AND f.ColumnName =b.name
WHERE a.name <> 'sysdiagrams' and c.name <> 'sysname'
ORDER BY a.name,b.column_Id
Consulta para generar diccionario de datos para MS SqlServer.
select
d.object_id,
a.name as [Tabla],
--schema_name(a.schema_id) schema_name,
--a.create_date,
b.name as [Columna],
c.name as [Tipo de dato],
CASE
WHEN c.name = 'numeric' OR c.name = 'decimal' OR c.name = 'float' THEN b.precision
ELSE null
END as [Precisión],
b.max_length as [Longitud],
CASE
WHEN b.is_nullable = 0 THEN 'No'
ELSE 'Si'
END as [Permite null],
CASE
WHEN b.is_identity = 0 THEN 'No'
ELSE 'Si'
END as [Es autonumérico],
ep.value as [Descripción],
f.ForeignKey as [Llave foranea (FK)],
f.ReferenceTableName as [FK: Tabla],
f.ReferenceColumnName as [FK: Columna]
from sys.tables a
inner join sys.columns b on a.object_id= b.object_id
inner join sys.systypes c on b.system_type_id= c.xtype
inner join sys.objects d on a.object_id= d.object_id
LEFT JOIN sys.extended_properties ep ON d.object_id = ep.major_id AND b.column_Id = ep.minor_id
LEFT JOIN (SELECT
f.name AS ForeignKey,
OBJECT_NAME(f.parent_object_id) AS TableName,
COL_NAME(fc.parent_object_id,fc.parent_column_id) AS ColumnName,
OBJECT_NAME (f.referenced_object_id) AS ReferenceTableName,
COL_NAME(fc.referenced_object_id,fc.referenced_column_id) AS ReferenceColumnName
FROM sys.foreign_keys AS f
INNER JOIN sys.foreign_key_columns AS fc ON f.OBJECT_ID = fc.constraint_object_id) f ON f.TableName =a.name AND f.ColumnName =b.name
WHERE a.name <> 'sysdiagrams' and c.name <> 'sysname'
ORDER BY a.name,b.column_Id
Comentarios
Publicar un comentario
Incluye información que aporte al tema