sql - Is there a generic way to 'insert if not exists' in MySQL? -


i have db dump , huge(nearly 150gb). want insert dump data schema has data. there identical rows , gives duplicate entry error when try import dump. there way "insert if not exists while importing dump"?

you can use insert on duplicate key update:

insert table1(id, col1, . . .)      select id, col1, col2, . .       table2      on duplicate key update id = values(id); 

for work, need unique index (or constraint) on id column(s). duplicates in column not allowed.

the on duplicate key part says update record when duplicate found. id = values(id) no-op. id set itself, nothing , effect of statement insert rows not in original table.


Comments

Popular posts from this blog

gcc - MinGW's ld cannot perform PE operations on non PE output file -

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

c# - Search and Add Comment with OpenXML for Word -