I need to alter several tables in one database. The following commands needs to be executed on each table:
alter table tbl modify column ID bigint(20) NOT NULL;
alter table tbl DROP PRIMARY KEY;
alter table tbl add column rowid int(11) NOT NULL AUTO_INCREMENT primary key;
alter table tbl ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin;
And to know which tables that needs to be altered, I do the following:
SELECT DISTINCT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME IN ('ID')
AND TABLE_SCHEMA='cpas2000ozkan';
This gives me a list of all the table names.
I can use these table names in a procedure. But I am new to this. Anyone can give me a hand with creating a procedure for doing this?
alter table tbl modify column ID bigint(20) NOT NULL;
alter table tbl DROP PRIMARY KEY;
alter table tbl add column rowid int(11) NOT NULL AUTO_INCREMENT primary key;
alter table tbl ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin;
And to know which tables that needs to be altered, I do the following:
SELECT DISTINCT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME IN ('ID')
AND TABLE_SCHEMA='cpas2000ozkan';
This gives me a list of all the table names.
I can use these table names in a procedure. But I am new to this. Anyone can give me a hand with creating a procedure for doing this?