1

I was looking into MySQL specification, but couldn't find any solution to my problem. I want to clone specific columns in several tables like this:

ALTER TABLE `table` ADD COLUMN `new_column` LIKE `column` AFTER `column`;

Of course this gives me syntax error: right syntax to use near 'LIKE `column` AFTER `column`', what i was expecting. Is there any possible solution to this or i have to specify directly a new column? I know that "cloning" table structure using LIKE operator is possible. Is it also possible in this case?

0

No. This is not possible using command.

All you can do is write a procedure to grab the table & column-name. Get the column definition from information_schema. Create alter-table-modify-column syntaxes & exec... Something like following:

call modify_table(target_table, source_table, source_column);

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.