# SQL If Exists Update Else Insert for bulk data

**URL:** <https://discourse.cakephp.org/t/sql-if-exists-update-else-insert-for-bulk-data/6773>\
**Category:** Need Help\
**Created:** [October 17, 2019, 8:58am UTC](https://discourse.cakephp.org/t/sql-if-exists-update-else-insert-for-bulk-data/6773 "2019-10-17T08:58:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Agalya05](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@Agalya05](https://discourse.cakephp.org/u/Agalya05)\
**Post date:** [October 17, 2019, 8:58am UTC](https://discourse.cakephp.org/t/sql-if-exists-update-else-insert-for-bulk-data/6773/1 "2019-10-17T08:58:23Z")

</div>

How can I do below query in Cakephp for bulk data arround 25k  
SQL query - If Exists Update Else Insert

if exists (select \* from table with (updlock,serializable) where key = @key)  
begin  
update table set …  
where key = @key  
end  
else  
begin  
insert into table (key, …)  
values (@key, …)  
end
