07/12/2010, 13:56
|
| | Fecha de Ingreso: abril-2010
Mensajes: 10
Antigüedad: 14 años, 8 meses Puntos: 0 | |
Respuesta: Como generar el diccionario de datos desde SQL Este script creo que es justo lo que buscas (SQL SERVER 2005)
Código:
select
d.object_id,
a.name [table],
--schema_name(a.schema_id) schema_name,
--a.create_date,
b.name [column],
c.name [type],
CASE
WHEN c.name = 'numeric' OR c.name = 'decimal' OR c.name = 'float' THEN b.precision
ELSE null
END [Precision],
b.max_length,
CASE
WHEN b.is_nullable = 0 THEN 'NO'
ELSE 'SI'
END [Permite Nulls],
CASE
WHEN b.is_identity = 0 THEN 'NO'
ELSE 'SI'
END [Es Autonumerico],
ep.value [Descripcion],
f.ForeignKey,
f.ReferenceTableName,
f.ReferenceColumnName
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'
ORDER BY a.name,b.column_Id
|