"mysql: alter ignore table add unique, what will be truncated?" Code Answer

4

the first record will be kept, the rest deleted §§:

ignore is a mysql extension to standard sql. it controls how alter table works if there are duplicates on unique keys in the new table or if warnings occur when strict mode is enabled. if ignore is not specified, the copy is aborted and rolled back if duplicate-key errors occur. if ignore is specified, only the first row is used of rows with duplicates on a unique key, the other conflicting rows are deleted. incorrect values are truncated to the closest matching acceptable value

i am guessing 'first' here means the one with the smallest id, assuming the id is the primary key.

also note:

as of mysql 5.7.4, the ignore clause for alter table is removed and its use produces an error.

By Sinh Ho on May 9 2022

Answers related to “mysql: alter ignore table add unique, what will be truncated?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.