In my database i have like 200 tables which starts from pre_table_XX( example : pre_table_1, pre_table_2, pre_table_3, pre_table_4 etc ). currently i need to add two new coloumns two all these tables by using a mysql query at once. below is an example of one of my tables
example table
trackID MyID Rid panelID timestamp useragent_browser useragent_OS
1 17 123 25 2014-04-29 10:02:01 Default Browser unknown NULL
2 17 123 25 2014-04-30 05:11:01 Default Browser unknown NULL
3 17 123 25 2014-05-15 06:44:02 Default Browser unknown NULL
4 17 59595 25 2014-10-06 07:50:30 Default Browser unknown 0
I need to add two new columns to each of these tables known as, device_name and browser
i tried it like this for no avail
SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema = 'abc_db' AND table_name LIKE 'pre_table_%'
ALTER TABLE `abc_db`.`stats`
ADD COLUMN `device_name` VARCHAR(45) NULL AFTER `useragent_os`,
ADD COLUMN `browser` VARCHAR(45) NULL AFTER `device_name`;
can anybody help on this. putting a mysql loop kind of thing would do i guess!!!