gpt4 book ai didi

SQL和存储过程中的多条语句

转载 作者:行者123 更新时间:2023-12-03 15:10:13 30 4
gpt4 key购买 nike

我正在使用 SQL Server 2005,并且有一个非常简单的存储过程:

create PROCEDURE [dbo].[tblTabel_Insert] 
@ID int,
@Code nvarchar(50) = null
AS
SET NOCOUNT ON;

IF EXISTS (SELECT ID, code FROM tblTabel WHERE ID = @ID and code = @Code)
UPDATE tblTabel SET ID = @ID,code = @Code WHERE ID = @ID

ELSE
BEGIN

INSERT INTO tblTabel (ID,code) VALUES ( @ID ,@Code);
END

我的问题是:在我的存储过程中是否可以有多个查询?
我想添加线条
UPDATE tblTabelB SET ID = @ID,code = @Code WHERE ID = @ID
UPDATE tblTabelC SET ID = @ID,code = @Code WHERE ID = @ID

在我的如果存在部分。如何以正确的方式更改我的存储过程?

最佳答案

IF  EXISTS (SELECT ID, code FROM tblTabel WHERE ID = @ID and code = @Code) 
BEGIN
UPDATE tblTabel SET ID = @ID,code = @Code WHERE ID = @ID
UPDATE tblTabelB SET ID = @ID,code = @Code WHERE ID = @ID
UPDATE tblTabelC SET ID = @ID,code = @Code WHERE ID = @ID
END

关于SQL和存储过程中的多条语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2432612/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com