insert if not exists

示例一:插入多条记录

假设有一个主键为 client_id 的 clients 表,可以使用下面的语句:

INSERT INTO clients ( client_id , client_name , client_type ) SELECT supplier_id , supplier_name , ' advertising ' FROM suppliers WHERE not exists ( select * from clients where clients . client_id = suppliers . supplier_id ) ;

示例一:插入单条记录

INSERT INTO clients ( client_id , client_name , client_type ) SELECT 10345 , ' IBM ' , ' advertising ' FROM dual WHERE not exists ( select * from clients where clients . client_id = 10345 ) ;

你可能感兴趣的:(not exists)