Ver Mensaje Individual
  #3 (permalink)  
Antiguo 27/05/2010, 13:38
ejbsoft
 
Fecha de Ingreso: febrero-2009
Mensajes: 312
Antigüedad: 15 años, 2 meses
Puntos: 4
Respuesta: Borrar tabla si exite

Cita:
Iniciado por siberiano Ver Mensaje
Código SQL:
Ver original
  1. IF object_id('dbo.yourtable') IS NOT NULL
  2. BEGIN
  3.   DROP TABLE dbo.yourtable
  4. END
Hola, una cuestión:

Si "dbo.yourtable" es una vista el drop table no funcionaría y daría error.

Yo siempre utilicé:

if exists (select * from sys.objects where name = 'dbo.yourtable' and type = 'U')
drop table dbo.yourtable
else
... lo q sea...

De todas maneras en SQL2008, al object_id hay que ponerle el nombre y tipo que falta en tu sentencia.
Quedaría así:

IF OBJECT_ID (N'dbo.yourtable', N'U') IS NOT NULL
drop table dbo.yourtable


Hay que especificar el tipo de objeto.

Saludos