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

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -