Ver Mensaje Individual
  #2 (permalink)  
Antiguo 03/08/2011, 14:30
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: Actualizar y borrar articulos en cascadas con TSQL

ON DELETE CASCADE is by far the quickest and the most direct solution. And if you don't want it to be permanent, why don't you have some T-SQL code that will switch this option on and off like here

remove the original Tbl_A_MyFK constraint (without the ON DELETE CASCADE)

ALTER TABLE Tbl_A DROP CONSTRAINT Tbl_A_MyFK

set the constraint Tbl_A_MyFK with the ON DELETE CASCADE

ALTER TABLE Tbl_A ADD CONSTRAINT Tbl_A_MyFK FOREIGN KEY (MyFK) REFERENCES Tbl_B(Column) ON DELETE CASCADE

Here you can do your delete

DELETE FROM Tbl_A WHERE ...

drop your constraint Tbl_A_MyFK

ALTER TABLE Tbl_A DROP CONSTRAINT Tbl_A_MyFK

set the constraint Tbl_A_MyFK without the ON DELETE CASCADE

ALTER TABLE Tbl_A ADD CONSTRAINT Tbl_A_MyFK FOREIGN KEY (MyFK) REFERENCES (Tbl_B)

Reference http://stackoverflow.com/questions/1...property-on-my


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