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. thanksHave 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
精彩评论