miércoles, 8 de diciembre de 2010

En SQLServer y Sybase como saber en que tablas existe un campo

EN SQLSERVER
* Muchas veces deseamos saber en que tablas encontramos algun campo.... es muy util el siguiente scrip para tal efecto, me ha sido de gran ayuda en muchas oportunidades....

select
obj.name TABLA, obj.xtype, obj.crdate, col.name CAMPO, col.xtype, col.lengthfrom syscolumns col, sysobjects objwhere col.id = obj.id and obj.name not like '%_INS%'and obj.name not like '%_UPD%'and obj.xtype = 'U'and col.name like '%nombre_del_campo%'order

* Aveces pasa que tenemos un campo de tipo datetime y solo necesitamos la fecha.... esto facilita las cosas

select dateadd(DAY,datediff(day,'2009-01-01',getdate()),'2009-01-01')
by obj.name

EN SYBASE
SELECT table_name FROM SYSTAB WHERE table_id IN (select table_id 
from SYSTABCOL

where COLUMN_NAME='nombre_del_campo')