2010-03-25 17 views

Respuesta

8

Esto es lo que pidió:

select 
    s.name as [Schema], 
    o.type_desc as [Type], 
    o.name as [Name] 
from 
    sys.all_objects o 
    inner join sys.schemas s on s.schema_id = o.schema_id 
where 
    o.type in ('U', 'V', 'P') -- tables, views, and stored procedures 
order by 
    s.name 
0

comienzo con

select * from sys.sysobjects 

EDIT: Ahora con el esquema

select * from sys.sysobjects 
inner join sys.schemas on sys.sysobjects.uid = sys.schemas.schema_id 
1

Puede crear una consulta utilizando las vistas del sistema INFORMATION_SCHEMA.TABLES, INFORMATION_SCHEMA.VIEWS y INFORMATION_SCHEMA.COLUMNS

Edit: Ah, y INFORMATION_SCHEMA.ROUTINES de almacenado procs

0

hay algunos construido en vistas del sistema que se puede utilizar:

  • sys.views
  • sys.tables
  • sys.procedures
  • sys.schema

Más información en MSDN aproximadamente Catalog Views.

0

TRY:

SELECT 
    ROUTINE_SCHEMA,ROUTINE_TYPE ,ROUTINE_NAME 
    FROM INFORMATION_SCHEMA.ROUTINES 
UNION 
SELECT 
    TABLE_SCHEMA,TABLE_TYPE,TABLE_NAME 
    FROM INFORMATION_SCHEMA.TABLES 
UNION 
SELECT 
    TABLE_SCHEMA,'VIEW' ,TABLE_NAME 
    FROM INFORMATION_SCHEMA.VIEWS 
    ORDER BY ROUTINE_SCHEMA,ROUTINE_TYPE ,ROUTINE_NAME 
0

probar este SQL si es necesario profundizar en las columnas y sus datos de tipo así. Puede utilizar estas opciones para sysobjects.xtype (T = tabla de usuario, P = proc almacenado, V = Vista)

SELECT object_type = sysobjects.xtype, 
    table_name = sysobjects.name, 
    column_name = syscolumns.name, 
    datatype = systypes.name, 
    length = syscolumns.length 
FROM sysobjects 
JOIN syscolumns ON sysobjects.id = syscolumns.id 
JOIN systypes ON syscolumns.xtype=systypes.xtype 
    WHERE sysobjects.xtype='U' AND 
syscolumns.name LIKE '%[column_name_here]%' 
AND sysobjects.name LIKE '%[table or Stored Proc Name]%' 
ORDER BY sysobjects.name,syscolumns.colid 
0

Ésta es la instrucción SQL que terminé usando:

SELECT 
     CASE so.type 
      WHEN 'U' THEN 'table' 
      WHEN 'P' THEN 'stored proc' 
      WHEN 'V' THEN 'view' 
     END AS [type], 
     s.name AS [schema], 
     so.[name] AS [name] 
FROM sys.sysobjects so 
JOIN sys.schemas s 
ON so.uid = s.schema_id 
WHERE so.type IN ('U', 'P', 'V') 
ORDER BY [type], [schema], [name] asc 
Cuestiones relacionadas