In MsSQL, commands similar to MySQL replace into remember a case in which MySQL was used many years ago. At that time, a requirement was raised when an additional item was added to the data table, determine whether the cursor exists. If the cursor is added when the cursor exists, update the token. Remember that at that time, the callback command was executed in the program.
1SELECT id FROM table WHERE id = 1;
In the program, determine whether the token has been added.
1insert into `table`(`id`,`value`)values(1,'new value');
Vice versa
1update `table` set value='new value' where id = 1;
After that, the replace into statement method can be used to compile the above functions only when it comes to MySQL.
1replace into `table`(`id`, `value`) values(1, 'new value');
When replace into is used, the data table must have a Primary Key or a Unique Key. Otherwise, replace into will directly add the data to the data table, causing a duplicate. What should I do on SQL Server? Before SQL 2008
1 UPDATE [table] 2 SET [value] = 'new value' 3WHERE [id] = 14 -- determine whether the token has been updated to the data 5if @ rowcount = 0 and @ error = 06 INSERT into [table] ([id], [value]) VALUES (1, 'new value') SQL 2008 (inclusive) later versions: 1 merge into [table] AS [t] USING (SELECT 1 AS [id]) AS [s] ON [t]. [id] = [s]. [id] 2 when matched THEN3 UPDATE4 SET [value] = 'new value' 5 when not matched THEN6 INSERT ([id], [value]) VALUES (1, 'New value ');