mysql 使用记号

时间:2024-07-02 09:03:56

1. 避免重复入库的插入记录方法

向一个数据库中插入且在未存在的情况下插入一行记录。若有主键可以区分则可以使用 replace into 方法,

单偏偏很多时候数据库设计者会设计自增主键,replace into 方式不便发挥作用,此时可使用 insert select

方式,如:

insert into mifc_se_adnw_app(ADNW, ADNWAppId)
   select 'a3msn', '1'
   from dual
   where not exists  (
        select *
        from mifc_se_adnw_app
        where ADNW='a3msn' and ADNWAppId='1'
   );

尽量参考这个格式,使用 dual 表名。