插入数据之前进行查看数据是否已经存在

INSERT INTO 数据表名称(字段1,字段2) 
SELECT 插入的值1,值2 FROM DUAL 
WHERE NOT EXISTS(SELECT * FROM 数据表名称
                WHERE 字段1= 值1 AND 字段2= 值2)
DUAL 不需要进行修改

 

INSERT INTO table(file1,file2,file3,file4,file5,file6) 
SELECT 1, 2,3,4,5,7 FROM DUAL 
WHERE NOT EXISTS(SELECT * FROM table
                        WHERE file1= 1 AND file2= 2 AND file3= 3
                        AND file4= 4 AND file5= 5 AND file6= 6)

 

posted @ 2021-08-26 10:14  CodeYaSuo  阅读(238)  评论(0编辑  收藏  举报