-1

Helo Folks,

I have 3 tables. A,B,C.

I have in Table A rows whose column'date' has value '2000-1-1'.

I like to delete rows from 3 tables based on where A.date = '2000-1-1'.

Considering a join on A.ID = B.ID.. or some other kind of join between tables.

Nishanthi Grashia
  • 9,787
  • 5
  • 42
  • 57
user3054077
  • 49
  • 1
  • 7

1 Answers1

1

You cannot issue a single delete statement against 3 table but you can wrap 3 delete statements against 3 different tables in One Transaction.

BEGIN TRANSACTION

    DELETE FROM TABLE_A
    WHERE EXISTS (SELECT 1
                  FROM Table_X X
                  WHERE TABLE_A.ID = X.ID)

    DELETE FROM TABLE_B
    WHERE EXISTS (SELECT 1
                  FROM Table_X X
                  WHERE TABLE_B.ID = X.ID)

    DELETE FROM TABLE_C
    WHERE EXISTS (SELECT 1
                  FROM Table_X X
                  WHERE TABLE_C.ID = X.ID)

COMMIT TRANSACTION;
M.Ali
  • 65,124
  • 12
  • 92
  • 119