SQl插入数据时判断是否存在,存在则跳过,不存在则插入
1 | insert into test(name) select 'test1' from DUAL WHERE NOT EXISTS(SELECT `name` from test where name = 'test1'); |
test是表明,test1是要插入的内容,name是对应的字段
首次执行结果
1 | [SQL] insert into test(name) select 'test1' from DUAL WHERE NOT EXISTS(SELECT `name` from test where name = 'test1'); |
第二次执行结果
1 | [SQL] insert into test(name) select 'test1' from DUAL WHERE NOT EXISTS(SELECT `name` from test where name = 'test1'); |