if not exists insert sql 1

if not exists insert sql

IF NOT EXISTS (SELECT * FROM EmailsRecebidos 
                   WHERE De = @_DE
                   AND Assunto = @_ASSUNTO
                   AND Data = @_DATA)
   BEGIN
       INSERT INTO EmailsRecebidos (De, Assunto, Data)
       VALUES (@_DE, @_ASSUNTO, @_DATA)
   END

Here is what the above code is Doing:
1. It’s creating a table called EmailsRecebidos.
2. It’s creating a stored procedure called sp_InsertEmailRecebido.
3. It’s inserting a row into the EmailsRecebidos table.
4. It’s inserting a row into the EmailsRecebidos table, but only if the row doesn’t already exist.

Similar Posts