I have a script file for MySQL This needs to is run on about databases. Here's a snippet: Alter TABLE <whatever_database>. ' tblusers ' add column availability ...< Span class= "PLN" >alter table<whatever_database>. ' tblusers< Span class= "pun" > ' add column ' reliability ' INTEGER ...
There is many more lines in the this script and I ' d like to automate it in a loop of the current databases to be updated. I ' ve got the list and the loop down using cursors, but here's where I ' m running into trouble: When I ' m on a particular database in the cursor, that database name was in a variable. I can ' t just say ALTER TABLE Curschema. tblusers Because the script complains that there is no database named Curschema (the name of the variable containing the database n Ame that I ' d like to run operations on). I ' ve been able to work around this by creating and executing a statement using parameters: SET @Curschema=Curschema;SET @Query= Null;SET @Email=EmailAddress;set @pass = Pass;set @statement = Concat ( ' SELECT userid into @query from ' , @curschema, ' .from @statementexecute Stmt
The problem is, setting up executable strings (like above) would become an extremely tedious task with the dozens of lines of code that I had to run. I was hoping this there was a a-to-I could set the current database for operations and then just reset that database E Ach loop Pass so my generic statements might is run: (Start of my loop) SET DATABASE Database0--(through to database29) --run statements with database0 .... Being implied with the above command Alter TABLE `Tblusers add column ' availability ' (1) UNSIGNED ... alter table tblusers add column ' reliability ' INTEGER UNSIGNED not ...
(End of my loop) Does such a command exist to set the current database on which operations could be performed? If No such command exists, is the there an easier-to accomplish my task? I figure so at this juncture it's just easier to does a find/replace on all the database names times than it's to REWR Ite my entire script file to is executable/parameter-ized strings. thanks! MySQL Database
ShareImprove this question |
edited Feb ' at 12:55 casperone57.4k< Span title= "Ten gold Badges" >10125 202 |
Asked at 16:49afilbert115 |
|