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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -