I would like to add same columns into my multiple tables at a time using bash script from my Linux virtual machine terminal. I have three tables in my database:
my_usa_table,
my_india_table,
my_germany_table
I want to add following columns for those three tables at a time.
ALTER TABLE my_{$i}table ADD COLUMN state VARCHAR(120) AFTER address;
ALTER TABLE my{$i}table ADD COLUMN zipcode VARCHAR(16) AFTER state;
ALTER TABLE my{$i}_table ADD COLUMN language VARCHAR(100) AFTER zipcode;
Here is my bash script:
#!/bin/bash
declare -a country=("usa","india","germany")
for i in "${country[@]}"
do
mysql -uroot -p testdb -e "ALTER TABLE my_{$i}_table ADD COLUMN state VARCHAR(120) AFTER address";
mysql -uroot -p testdb -e "ALTER TABLE my_{$i}_table ADD COLUMN zipcode VARCHAR(16) AFTER state";
mysql -uroot -p testdb -e "ALTER TABLE my_{$i}_table ADD COLUMN language VARCHAR(100) AFTER zipcode";
done
But it is getting error. How may i fix it please ?
";by;".