Home > database >  SQL server into multiple data, if there are changes, there is no insert, how to write
SQL server into multiple data, if there are changes, there is no insert, how to write

Time:01-01

Have a target table and a source table, need to list the source of information is inserted into the target table

CodePudding user response:

Use the MERGE for
https://blog.csdn.net/sinat_28984567/article/details/79861811

CodePudding user response:

The upstairs is better,
 IF the EXISTS (SELECT * FROM Table1 WHERE Id=@ Id) 

The BEGIN

The UPDATE Table1 SET Column1=@ newValue WHERE Id=@ Id

END

The ELSE

The BEGIN

INSERT INTO Table1 (Id, Column1) VALUES (@ Id, @ newValue)

END
  • Related