2

table 1 :

idtb1 --pk
published
delete

table 2 :

idtb2 --pk
idtb1 --fk
published
delete

how to update 2 column published ,delete on 2 table together by command Update

avkkamsy
  • 57
  • 6

1 Answers1

4

You can't update more than one table in a single statement

       BEGIN TRANSACTION

       update A
       set A.published =  @published
       from table1 A 
       inner join table2 B on B.idtb1 = A.idtb1

      update B
      set B.published = @published 
      from table2 B 
      inner join table1 A on B.idtb1 = A.idtb1

      COMMIT

This question already has an answer here

Community
  • 1
  • 1
Jande
  • 1,695
  • 2
  • 20
  • 32