开发者

SQL Execute Insert or Update based if the Data is already in the Table

is it possible to execute a query that inserts the Row if the ID don't exist and Update the Row if the ID already exists in a single sql statment?

i mean not using stored procudures just plain SQL.

i already doing LoadRecord and if noone returned then insert and if any record is returned then update.

but i wanted to know if there is any way to do it without hit开发者_C百科ting on the DB server Twice.

The ID field is an integer Primary Key that is not an auto incriment.

thanks


Have a look at

  • MERGE (Transact-SQL)
  • SQL SERVER – 2008 – Introduction to Merge Statement – One Statement for INSERT, UPDATE, DELETE
  • Using SQL Server 2008's MERGE statement
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜