Created
December 23, 2022 21:07
-
-
Save larrasket/dd42cc5bd865bccec953a4a5cd2583f4 to your computer and use it in GitHub Desktop.
SQL Server, delete if exists, insert if doesn't exist (aka toggle)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MERGE INTO SIJL.USERS AS target | |
USING ( | |
SELECT '<username>' AS username, '<email>' AS email | |
) AS source | |
ON (target.username = source.username AND target.email = source.email) | |
WHEN MATCHED THEN | |
DELETE | |
WHEN NOT MATCHED THEN | |
INSERT (hash, first_name, last_name, email, username, age) | |
VALUES (HASHBYTES('SHA2_256', '<password>'), '<first_name>', '<last_name>', '<email>', '<username>', <age>) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment