MySql【Insert Select Not Exist】判断记录再添加值的方案

MySql【Insert Select Not Exist】判断记录再添加值的方案

INSERT INTO content (
detail,
status,
beginTime,
endTime)
SELECT
@detail,
1,
NULL,
NULL
FROM DUAL
WHERE NOT EXISTS(
SELECT contentId
FROM content
WHERE detail=@detail);

INSERT INTO table(column1,column2,column3 ...columnN)  
SELECT value1,value2,value3 ...valueN  
FROM dual  
WHERE NOT EXISTS(  
      SELECT *  
      FROM table  
      WHERE value = ?  
);

MySql【Insert Select Not Exist】判断记录再添加值的方案
https://www.dearcloud.cn/2016/04/13/20200310-cnblogs-old-posts/20160413-MySql【InsertSelectNotExist】判断记录再添加值的方案/
作者
宋兴柱
发布于
2016年4月13日
许可协议