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?

asked Mar 29, 2016 at 5:22

1 Answer 1

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);

answered Mar 29, 2016 at 6:39
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.