Mysql向数据库插入数据时,判断是否存在,若不存在就插入数据

表中一定要有主键  :

 select :id,此处的id位置处必须是主键
1 insert into table_name(id, name, password) 
2                         select :id, :name, :password 
3                          from dual
4                       where not exists ( 
5                        select * from table_name
6                        where id = :id )
原文地址:https://www.cnblogs.com/wdpnodecodes/p/8025202.html