Ver Mensaje Individual
  #2 (permalink)  
Antiguo 02/11/2012, 16:02
Avatar de Libras
Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 17 años, 8 meses
Puntos: 774
Respuesta: unir dos scripts delete

no se pueden eliminar registros de 2 tablas en el mismo query, lo que puedes hacer es si tienen dependencia hacer un borrado en cascada :)


A DELETE statement will only delete from one table, but there are ways.

http://msdn.microsoft.com/en-us/library/ms174979.aspx
You could define Foreign Key constraints for the other tables that reference
the master table's ProductID with ON DELETE CASCADE. This would cause the
related rows in those tables to be deleted. This is the least programming
model, is part of the SQL standard, etc. Just be sure that you think through
the issues with always deleting the referencing rows.

http://msdn.microsoft.com/en-us/library/ms189799.aspx
You could create a delete trigger on the table where you delete the master
row for the ProductID that would then contain code to delete related rows
from other tables. You still have to write the code for this one, but it
hides inside the trigger and is used by any deletes from the table as long
as the trigger is not disabled.

saludos!!
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me

Última edición por Libras; 02/11/2012 a las 16:12