I have a project in C# with a Sql-server Database.
In that database I have a table named 'Process' and columns named 'process_name', 'Full_Name' and 'Version' (all of the type:nvarchar(50)).
I want to write a query wich will add the new process, only if it doesn't exist in the table yet.
How can I do that?
Many thanks,
IF NOT EXISTS (SELECT * FROM Process WHERE process_name = 'xxx')
INSERT INTO Process (process_name, Full_Name, Version)
VALUES ('xxx', 'yyy', 'zzz')
You might be interested in the MERGE command which is new to SQL Server 2008.
http://technet.microsoft.com/en-us/library/bb510625.aspx
This allows you to insert rows that don't exist or update records that do exist all in one statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With