Dong Lam Trien

Dong Lam Trien

  • 780
  • 945
  • 132k

SQL Server delete data with Linked Table ?

Sep 24 2017 10:15 PM
Suppose you have 3 tables: TABHDBH, TABHDBHCHUYEN and TABHDBHCT
 
Table TABHDBH has the following fields:
NGAY DateTime;
IDHDBH int
...
 
Table IDHDBHCT has the following fields:
MAHDBH int
...
 
TABHDBHCHUYEN
NGAYCHUYEN datetime
MAHDBH int
...
 
RELATIONSHIP OF 3 TABLE
TABHDBHCHUYEN.MAHDBH head n
TABHDBH.IDHDBH head 1
TABHDBHCT.MAHDBH head n
  1. DELETE T1 FROM TABHDBHCHUYEN T1 INNER JOIN TABHDBH T2 ON T1.MAHDBH = T2.IDHDBH INNER JOIN TABHDBHCT T3 ON T2.IDHDBH = T3.MAHDBH WHERE (CONVERT(VARCHAR, NGAYCHUYEN, 101) <= '01/07/2017')  
When running the query without error only delete the 1 record in TABHDBHCHUYEN and the records in the other 2 TABLE not delete record, you see help me wrong? Created a relational table for 3 tables to Delete Rule mode to Cascade but not delete.

Answers (2)