I have a MySQL table defined as so:
create table MyTable2 (
ID bigint unsigned NOT NULL AUTO_INCREMENT,
Field2 varchar(4096) CHARACTER SET utf8 NOT NULL,
Field3 varchar(256) CHARACTER SET utf8 NOT NULL,
Field4 varchar(64) NOT NULL,
ForeignID bigint unsigned NOT NULL,
DateAdded TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY(ID),
FOREIGN KEY fk_ForeignID(ForeignID) REFERENCES MyTable1(ID)
ON UPDATE CASCADE ON DELETE RESTRICT);
I want to insert a bunch of new records. However, if a record exists where Field2, Field3, Field4 and ForeignID match I want to ignore. IOW, if a record matches but not the DateAdded field or the ID (which is auto added) then I want to ignore the insert. But I want to add any where these 4 fields do not match already.
Is this possible with a MYSQL INSERT command alone or do I need to do some magic where I compare the values in existing records against these 4 fields?
I tried with INSERT IGNORE INTO setting a record matching these 4 fields and the new record was added with a new ID and DateAdded field which is NOT what I want.