-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.

ngrashia
  • 9,869
  • 5
  • 43
  • 58
user3054077
  • 49
  • 2
  • 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
  • 67,945
  • 13
  • 101
  • 127