我想知道存储过程中是否可以有多个Update语句
像这样的东西:
Update Table1 set field1 = @new_value where id = @table1_id Update Table2 set field2 = @new_value where id = @table2_id Update Table3 set field3 = @new_value where id = @table3_id
现在,我将单独执行它们,但是由于它们只能一起使用,所以我想知道它们是否可以仅位于一个SP中。
是的,有可能:
CREATE PROCEDURE prc_update (@table1_id INT, @table2_id INT, @table3_id INT, @new_value INT) AS BEGIN UPDATE Table1 SET field1 = @new_value WHERE id = @table1_id UPDATE Table2 SET field2 = @new_value WHERE id = @table2_id UPDATE Table3 SET field3 = @new_value WHERE id = @table3_id END