viernes, 10 de noviembre de 2017

Consultar si existe un índice en una tabla

IF EXISTS (select * from sys.indexes where object_id = (select object_id from sys.objects where name = 'DTE_recibos') and name ='fecha_emision')
print 'ok'
else
print 'bad'


IF EXISTS (SELECT * FROM sys.indexes WHERE
object_id = (SELECT object_id FROM sys.objects WHERE name = 'DTE_recibos') AND name ='fecha_emision')
BEGIN
DROP INDEX fecha_emision on dbo.DTE_recibos
END
ELSE
BEGIN
print '435345'
END

No hay comentarios.:

Publicar un comentario