一句话解决更新和插入的问题
if exists(select 1 from Pat_ResultScores where SID=:SID) update Pat_ResultScores set Scores=:Scores,UserY=:UserY,UserP=:UserP where SID=:SID else insert into Pat_ResultScores(SID,Scores,UserY,UserP) values(:SID,:Scores,:UserY,:UserP)
本文介绍了一种使用SQL语句高效处理记录更新与插入的方法。通过一个条件判断结构,该方法能够在记录存在时进行更新操作,而在记录不存在时执行插入操作,有效避免了重复数据并简化了数据库维护工作。
一句话解决更新和插入的问题
if exists(select 1 from Pat_ResultScores where SID=:SID) update Pat_ResultScores set Scores=:Scores,UserY=:UserY,UserP=:UserP where SID=:SID else insert into Pat_ResultScores(SID,Scores,UserY,UserP) values(:SID,:Scores,:UserY,:UserP)

被折叠的 条评论
为什么被折叠?