report - Getting the affected rows when altering a table in mysql -
i need retrieve report of affected rows when table has been altered following commands:
1.- changing engine:
alter table <table> engine=innodb;
2.- adding constraints:
alter table nombre_tabla add primary key símbolo_clave_foránea; alter table nombre_tabla drop primary key símbolo_clave_foránea; alter table nombre_tabla add foreign key símbolo_clave_foránea; alter table nombre_tabla drop foreign key símbolo_clave_foránea;
3.- adding unique constraint.
primary or unique key failure duplicates, if have nulls in there you'll need sort them first.
e.g given mytable(keyfield int not null)
then
select keyfield mytable inner join (select keyfield,count() numberoftimes group keyfield) duplicates numberoftimes > 1
then you'll have come them. delete or rekey.
foreign keys outer join query key null
e.g given mytable (keyfield int not null, foreignkeyfield int not null)
, mylookuptable(lookupkey int not null, description varchar(32) not null)
then
select keyfield mytable left join mylookuptable on mytable.lookupfield = mylookuptable.lookupkey mytable.lookupfield null
again you'll have decide them. delete them, might help. 1 way insert "missing" record in table, grab it's key, update join. given key 999
update m set lookupfield = 999 mytable m left join mylookuptable on m.lookupfield = mylookuptable.lookupkey m.lookupfield null
now can dig out 999s , deal them @ leisure.
Comments
Post a Comment