insert into table if not exists code example

Example 1: drop table if exists

DROP TABLE IF EXISTS dbo.Scores

Example 2: 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

Example 3: mysql insert into if not exists

INSERT INTO table_name (firstname, lastname)
SELECT 'NEW FIRSTNAME', 'NEW LASTNAME'
FROM DUAL
WHERE NOT EXISTS(
    SELECT 1
    FROM table_name
    WHERE firstname = 'NEW FIRSTNAME' AND lastname = 'NEW LASTNAME'
)
LIMIT 1;

Example 4: mysql insert if not exists

INSERT IGNORE INTO companies
    (id, full_name, address, phone_number)
VALUES
    (1, 'Apple', '1 Infinite Loop, Cupertino, California', 18002752273);

Example 5: php sql insert into if not exists

INSERT IGNORE INTO `transcripts`
SET `ensembl_transcript_id` = 'ENSORGT00000000001',
`transcript_chrom_start` = 12345,
`transcript_chrom_end` = 12678;