I am trying to add a column called UpdateT2 to all the tables (without knowing their names) in my database.
I am running the following script:
SET @DatabaseName = "intermedia";
SET @ColumnName= " UpdateT2 TIMESTAMP";
Select Concat ('ALTER TABLE ', TABLE_NAME, ' Add' , @ColumnName, ' DEFAULT CURRENT_TIMESTAMP;') as QUERY
From information_schema.tables
where table_schema = @DatabaseName;
The script runs correctly, that is, it does not give any errors, but the column is not added to the tables.
Instead, if I run a: ALTER TABLE mytable ADD UpdateT2 TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
It works perfectly and adds the column to the table.
Why in the first case it doesn’t work? What is the difference?