SQL 利用存储过程实现对表数据有则更新无则添加
/*建立存储过程*/
create procedure insertOrUpdate
@BookName varchar (50),
@Price float,
@Publish varchar (50),
@id int,
@Storage int,
@returnValue int output
as
/*判断该id号的书是否已经存在*/
if exists (select * from Book where id=@id)
begin
/*更新数据*/
update Book set BookName=@BookName ,Price=@Price where id=@id
/*设置返回值*/
set @returnValue=0
end
else
begin
/*插入*/
insert into Book values(@BookName,@Price,@Publish,@id,@Storage)
set @returnValue=1
end
本文来自博客园,作者:꧁༺星星的轨迹方程式༻꧂,转载请注明原文链接:https://www.cnblogs.com/SuSVIP/p/16741339.html