Guest User

Untitled

a guest
Nov 22nd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. select
  2. d.object_id,
  3. a.name [table], -- identificara la Tabla
  4. b.name [column], -- identificara la columna
  5. c.name [type], -- identificara el Tipo
  6. CASE-- recibe el tipo de columna
  7. --cuando c es numerico o c es decimal o c es Float entonces se precisa el numero
  8. WHEN c.name = 'numeric' OR c.name = 'decimal' OR c.name = 'float' THEN b.precision
  9. ELSE null
  10. END [Precision],
  11. -- recibe maximo tamaño de b
  12. b.max_length,
  13. CASE -- recibe si la columna acepta nulos
  14. WHEN b.is_nullable = 0 THEN 'NO'
  15. ELSE 'SI'
  16. END [Permite Nulls],
  17. CASE -- recibe si la columna es identity (autoincrementable)
  18. WHEN b.is_identity = 0 THEN 'NO'
  19. ELSE 'SI'
  20. END [Es Autonumerico],
  21. ep.value [Descripcion],-- recibe la descripcion de la columna(si la hay)
  22. f.ForeignKey, -- recibe si es llave foranea
  23. f.ReferenceTableName, -- recibe la referencia de la tabla
  24. f.ReferenceColumnName -- recibe la referencia de la columna
  25. from sys.tables a
  26. -- // Seleciona y muestra toda la informacion \\ --
  27. inner join sys.columns b on a.object_id= b.object_id
  28. inner join sys.systypes c on b.system_type_id= c.xtype
  29. inner join sys.objects d on a.object_id= d.object_id
  30. LEFT JOIN sys.extended_properties ep ON d.object_id = ep.major_id AND b.column_Id = ep.minor_id
  31. LEFT JOIN (SELECT
  32. f.name AS ForeignKey,
  33. OBJECT_NAME(f.parent_object_id) AS TableName,
  34. COL_NAME(fc.parent_object_id,fc.parent_column_id) AS ColumnName,
  35. OBJECT_NAME (f.referenced_object_id) AS ReferenceTableName,
  36. COL_NAME(fc.referenced_object_id,fc.referenced_column_id) AS ReferenceColumnName
  37. FROM sys.foreign_keys AS f
  38. 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
  39. WHERE a.name <> 'sysdiagrams'
  40. ORDER BY a.name,b.column_Id
Add Comment
Please, Sign In to add comment