“Заявление SQL Merge” Ответ

TSQL Merge Пример

MERGE esqlProductTarget T
USING esqlProductSource S
ON (S.ProductID = T.ProductID)
WHEN MATCHED 
     THEN UPDATE
     SET    T.Name = S.Name,
            T.ProductNumber = S.ProductNumber,
            T.Color = S.Color
WHEN NOT MATCHED BY TARGET
THEN INSERT (ProductID, Name, ProductNumber, Color)
     VALUES (S.ProductID, S.Name, S.ProductNumber, S.Color)
WHEN NOT MATCHED BY SOURCE
THEN DELETE;
Jittery Jellyfish

SQL Merge

-- Oracle: Example for Insert or update in t1 from t2 values 
MERGE INTO table1 t1
USING table2 t2
ON (t1.CODE = t2.ID)
WHEN MATCHED THEN
    UPDATE SET t1.COL1 = t2.VALUE1
WHEN NOT MATCHED THEN
    INSERT (CODE, COL1)  VALUES (t2.ID, t2.VALUE1);
VasteMonde

SQL Merge

MERGE target_table USING source_table
ON merge_condition
WHEN MATCHED
    THEN update_statement
WHEN NOT MATCHED
    THEN insert_statement
WHEN NOT MATCHED BY SOURCE
    THEN DELETE;
Code language: SQL (Structured Query Language) (sql)
Curious Crab

Заявление SQL Merge

MERGE LoginTypes T
        USING (SELECT 'System' as Description) S
        ON(S.Description = T.Description)
WHEN NOT MATCHED BY TARGET
    THEN INSERT(Description, CreatedTimestamp, LastUpdatedTimestamp)
VALUES('System', getdate(), getdate());
Frightened Finch

Команда Merge в SQL

USE SqlShackMergeDemo
GO
    
MERGE TargetProducts AS Target
USING SourceProducts	AS Source
ON Source.ProductID = Target.ProductID
    
-- For Inserts
WHEN NOT MATCHED BY Target THEN
    INSERT (ProductID,ProductName, Price) 
    VALUES (Source.ProductID,Source.ProductName, Source.Price)
    
-- For Updates
WHEN MATCHED THEN UPDATE SET
    Target.ProductName	= Source.ProductName,
    Target.Price		= Source.Price
    
-- For Deletes
WHEN NOT MATCHED BY Source THEN
    DELETE;
rohit

Ответы похожие на “Заявление SQL Merge”

Вопросы похожие на “Заявление SQL Merge”

Больше похожих ответов на “Заявление SQL Merge” по Sql

Смотреть популярные ответы по языку

Смотреть другие языки программирования