欢迎来到我的的博客园,祝大家学有所成,早点实现自己的人生理想。

SqlServer和Mysql插入记录前判断是否存在,存在则插入,不存在则修改。


SqlServer中是这样:

if NOT exists(SELECT * FROM Setting WHERE ID=0)
INSERT INTO Setting(ID,Title,SearchKeys, ServiceIntervalSecond,SleepMillisecondPerSearch) VALUES(0,@title,@searchKeys,@serviceIntervalSecond,@sleepMillisecondPerSearch) 
ELSE 
UPDATE Setting SET Title=@title,SearchKeys=@searchKeys,ServiceIntervalSecond=@serviceIntervalSecond, SleepMillisecondPerSearch=@sleepMillisecondPerSearch

 

MySqL中是这样:

INSERT INTO `his_examine_result` (Mid,His_Examine_Mid, His_File_Mid, ResultType, His_Employee_Mid,
                                  His_Employee_Name, ExamineResult, ExamineItemName, ExamineStandardName, 
                                  ExamineItemUnit, ExamineHighValue, ExamineLowValue, ExamineDiscription, Discription)
    VALUES ($mid,$examineMid,$fileMid,1,null,null,'',$itemName,$standName,$itemUnit,$highValue,$lowValue,'','') 
ON DUPLICATE KEY UPDATE ExamineResult=$result,ExamineDiscription=$dis

 

posted @ 2017-02-04 11:40  宋兴柱  阅读(13494)  评论(1编辑  收藏  举报