sql - MySQL Order of Index Checks -


i running mysql , have simple table below:

create table `new_schema`.`test1` (   `id` int not null auto_increment,   `unique1` varchar(45) null,   `unique2` varchar(45) null,   primary key (`id`),   unique index `unique1_unique` (`unique1` asc),   unique index `unique2_unique` (`unique2` asc)); 

i add row such:

insert `new_schema`.`test1` (`unique1`, `unique2`) values ('x', 'x'); 

i add row same values in unique unique columns:

insert `new_schema`.`test1` (`unique1`, `unique2`) values ('x', 'x'); 

i error expected:

11:54:06    insert `new_schema`.`test1` (`unique1`, `unique2`) values ('x', 'x')   error code: 1062. duplicate entry 'x' key 'unique1_unique'  0.203 sec 

my question is, how change order in mysql checks unique values entered. so, given example above, provided 2 violations of unique entries (unique1 , unique2), want check unique2 first, error this:

11:54:06    insert `new_schema`.`test1` (`unique1`, `unique2`) values ('x', 'x')   error code: 1062. duplicate entry 'x' key 'unique2_unique'  0.203 sec 

thanks, mark

have trie change position that

    unique key index `unique_unique` (`unique2`,`unique1`) 

like that:

 create table `new_schema`.`test1` (    `id` int not null auto_increment,    `unique1` varchar(45) null,    `unique2` varchar(45) null,   primary key (`id`),  unique key index `unique_unique` (`unique2`,`unique1`)  ); 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -