Software Lab

SQL – consultas útiles de estructura de bases de datos, campos, vistas, etc

Dic
12


–¿Cómo buscar por nombre de campo en todos los objetos de la base de datos?

SELECT sysobjects.name AS table_name, syscolumns.name AS column_name,
systypes.name AS datatype, syscolumns.LENGTH AS LENGTH
FROM sysobjects INNER JOIN
syscolumns ON sysobjects.id = syscolumns.id INNER JOIN
systypes ON syscolumns.xtype = systypes.xtype
WHERE 1=1
–and (sysobjects.xtype = ‘U’) /*U=SOLO TABLAS*/
and (UPPER(syscolumns.name) like upper(‘%lopd%’))
ORDER BY sysobjects.name, syscolumns.colid

 

–¿Cómo consultar la definición de una Vista?

SELECT definition, uses_ansi_nulls, uses_quoted_identifier, is_schema_bound
FROM sys.sql_modules
WHERE object_id = OBJECT_ID(‘vRG_Clientes_DatosAux’);

Deja un comentario