“Pernyataan Gabungan SQL” Kode Jawaban

Contoh Gabungan TSQL

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

gabungan sql

-- 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

Gabungan sql

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

Pernyataan Gabungan SQL

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

Perintah gabungan di 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

Jawaban yang mirip dengan “Pernyataan Gabungan SQL”

Pertanyaan yang mirip dengan “Pernyataan Gabungan SQL”

Lebih banyak jawaban terkait untuk “Pernyataan Gabungan SQL” di Sql

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya