Monday, March 29, 2010

sql insert check firstly exists

inserting any record if you do not want to insert duplicate records
you should write insert query like


--ORACLE
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);


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

for details
click

No comments: