sql server merge 做insert和update
CREATE TABLE test1 (id INT, f1 VARCHAR(10),f2 VARCHAR(10),f3 VARCHAR(10))
GO
INSERT INTO test1 SELECT 1,1,1,1
INSERT INTO test1 SELECT 1,2,2,2
go
CREATE TABLE test2 (id INT, f5 VARCHAR(10),f6 VARCHAR(10))
GO
SELECT * FROM dbo.test1
GO
SELECT * FROM dbo.test2
GO
CREATE PROC sp_test AS
BEGIN
MERGE INTO test2 T1
USING (SELECT id,f3,f2 FROM test1) T2
ON ( T1.id=T2.id)
WHEN MATCHED THEN
UPDATE SET T1.f5 = T2.f2,t1.f6=t2.f3
WHEN NOT MATCHED THEN
INSERT (id,f5,f6) VALUES(t2.id,t2.f2,t2.f3);
END
GO
EXEC sp_test
GO
SELECT * FROM dbo.test1
GO
SELECT * FROM dbo.test2
GO
相關文章
- SQL Server的Merge —— 一步實現 insert,update,deleteSQLServerdelete
- sql server 帶有OUTPUT的INSERT,DELETE,UPDATESQLServerdelete
- SQL Server 2008中SQL增強之三:Merge(在一條語句中使用Insert,Update,Delete)SQLServerdelete
- MERGE新特性(UPDATE WHERE,DELETE WHERE,INSERT WHERE)delete
- Sql server with as update用法SQLServer
- Merge into: Oracle中用一條SQL語句直接進行Insert/Update的操作(R1)OracleSQL
- sql server merge 的用法SQLServer
- Sql Server系列:Update語句SQLServer
- Sql Server系列:Insert語句SQLServer
- LINQ to SQL語句之Insert/Update/Delete操作SQLdelete
- MySql與Sql Server Update語句MySqlServer
- Sqlserver、oracle中Merge的使用方法,一個merge語句搞定多個Insert,Update,Delete操作SQLServerOracledelete
- 用merge 語句代替 insert 和deletedelete
- ORACLE sql merge into update where條件位置與效能消耗OracleSQL
- SQL Server中的Merge關鍵字SQLServer
- Oracle中 Update和insert結合語法Oracle
- SQL Server 2008 MERGE語法SQLServer
- mysql INSERT ... ON DUPLICATE KEY UPDATEMySql
- Oracle\MS SQL Server Update多表關聯更新OracleSQLServer
- 利用insert,update和delete注入獲取資料delete
- 模擬insert,update和delete造成阻塞的示例delete
- SQL Server Bulk Insert批量資料匯入SQLServer
- Hive學習筆記 ---- 支援Update和Delete以及MergeHive筆記delete
- lightdb -- merge into insert 相容 OracleOracle
- SQL SERVER的UPDATE操作比ORACLE快得多SQLServerOracle
- Sql server 的update語句的新認識SQLServer
- SQL Server Insert時開啟顯式事務SQLServer
- Default Locking for INSERT, UPDATE, DELETE, and SELECT ... FOR UPDATE (351)delete
- sql merge intoSQL
- MySQL insert on duplicate key update 死鎖MySql
- 34、VIEW可以insert,delete,update.Viewdelete
- Laravel5.6 如何列印 SQL?insert/update/select 列印方法總結LaravelSQL
- SQL Server 2008 優化MERGE語句效能SQLServer優化
- SQL Server 2008中的新語句:MERGESQLServer
- 簡單練習Microsoft SQL Server MERGE同步兩個表ROSSQLServer
- update修改為merge(max+decode)
- java-Mybatis XML 對映器(select,insert, update 和 delete)JavaMyBatisXMLdelete
- mybatis 批量新增insert、更新update詳解MyBatis