Skip to content

Instantly share code, notes, and snippets.

@kkoziarski
Last active June 18, 2016 13:33
Show Gist options
  • Save kkoziarski/bb9831cde953836df9ae4ab5eb6974be to your computer and use it in GitHub Desktop.
Save kkoziarski/bb9831cde953836df9ae4ab5eb6974be to your computer and use it in GitHub Desktop.
Script.PostDeployment.sql update or insert (MERGE)
MERGE INTO [TABLE_NAME]
USING (VALUES
(1, 'some text', 'some value'),
(2, 'some text', 'some value')
)
AS Source ([ID], [Text], [Value])
ON [TABLE].[ID] = Source.[ID]
-- update matched rows
WHEN MATCHED THEN
UPDATE SET
[Text] = Source.[Text],
[Value] = Source.[Value]
-- insert new rows
WHEN NOT MATCHED BY TARGET THEN
INSERT ([ID], [Text], [Value])
VALUES ([ID], [Text], [Value])
--Script.PostDeployment.sql
--BEGIN
--:r .\Data\post_data.sql
--END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment