MERGE INTO KULLANIMI

Merge ;

Merge komutu veritabanına insert işlemi yaparken kayıt varsa update , kayıt yoksa insert etmeye yarayan çok faydalı bir komuttur.Özellikle tablodan tabloya insert-update işlemleri için merge komutu oldukça kullanışlıdır.

Örnek -1 :

MERGE INTO AccountBase as ac
USING(

VALUES (‘12313123123′,’+90(123123)1231231231232′),(‘123123132213′,’+90(123123)12312312313′)

) AS X (AccountNumber, Fax)

ON ac.AccountNumber = X.AccountNumber
WHEN MATCHED THEN
UPDATE SET ac.Fax = X.Fax;
WHEN NOT MATCHED THEN
INSERT (AccountNumber, Fax) VALUES(X.AccountNumber, X.Fax);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: