标签:
转自:http://hi.baidu.com/tidy0608/item/ff930fe2436f2601560f1dd9
sqlsever数据存在就更新,不存在就插入的两种方法
1. Update, if @@ROWCOUNT = 0 then insert
UPDATETable1 SETColumn1 = @newValue WHEREId = @id
IF@@ROWCOUNT= 0
BEGIN
INSERT INTOTable1 (Id, Column1) VALUES(@id, @newValue)
END
2. If row exists update, otherwise insert
IFEXISTS(SELECT* FROMTable1 WHEREId = @id)
BEGIN
UPDATETable1 SETColumn1 = @newValue WHEREId = @id
END
ELSE
BEGIN
INSERT INTOTable1 (Id, Column1) VALUES(@id, @newValue)
END
3.mysql数据存在就更新,不存在就插入
insert into T(f1,f2,f3) values(v1,v2,v3) on DUPLICATE KEY UPDATE v3=values(v3)+v3
sql mysql和sqlserver存在就更新,不存在就插入的写法(转)
标签:
原文地址:http://www.cnblogs.com/newlangwen/p/4810734.html