How to update two or more table usin one Stored Procedure

  • Hi All,

    I am not so much aware of writing SP in sql , can i write a sp which can update two or more tables , if yes then please give me an example.

    Thanks in advance

     

     

  • Yes.  Just use two seperate update statements

     

    create procedure usp_UpdateTwoTables

    as

    begin

    update table1

    set Column1 = 'a'

    update table2

    set Column2 = 'b'

    end

  • create procedure usp_UpdateTables

        @value varchar(50)

    as

    BEGIN

    UPDATE table1

        SET col1 = @value

    UPDATE table2

        SET colA = @value

    END

    Gordon Pollokoff

    "Wile E. is my reality, Bugs Bunny is my goal" - Chuck Jones

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply