Ver Mensaje Individual
  #12 (permalink)  
Antiguo 07/11/2012, 03:43
ejbsoft
 
Fecha de Ingreso: febrero-2009
Mensajes: 312
Antigüedad: 15 años, 2 meses
Puntos: 4
Respuesta: unir dos scripts delete

Cita:
Iniciado por Libras Ver Mensaje
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!!
Hola, no se si estoy en lo cierto pero si se ponen 2 DELETES a continuación de un BEGIN, tipo:

BEGIN TRANSACTION
DELETE TABLE1...
DELETE TABLE2...
COMMIT / ROLLBACK TRANSACTION

No valdría con esta forma para que sea una misma query o en este caso transacción?
Saludos