ALTER A DATA TYPE.

HI ALL,
IS THERE A WAY I CAN  ALTER A DATA-TYPE  OF A COLUMNS OF ALL TABLES IN A DATABASE WITH SINGLE COMMAND LINE IN MySQL

THANKS
RotebergAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mukesh YadavFull Stack DeveloperCommented:
You can check column data type by checking table structure.

desc <tableName>;

Open in new window

0
Ryan ChongCommented:
in the case for multiple tables you will need multiple Alter Table SQL statements
1
Vikas GargBusiness Intelligence DeveloperCommented:
Hi,

You can use this

ALTER TABLE webstore.Store
  MODIFY COLUMN ShortName VARCHAR(100),


If you want to change all columns of a certain type to another type, you can generate queries using a query like this:

select distinct concat('alter table ',
                       table_name,
                       ' modify ',
                       column_name,
                       ' <new datatype> ',
                       if(is_nullable = 'NO', ' NOT ', ''),
                       ' NULL;')
  from information_schema.columns
  where table_schema = '<your database>' 
    and column_type = '<old datatype>';

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Ryan ChongCommented:
alternatively, you can create a Stored Procedure (SP) which loop through the user tables with Alter Table SQL statements, and then you may call that SP to do the work.
0
RotebergAuthor Commented:
Thanks Vikas!

i will try this command.
0
RotebergAuthor Commented:
Thanks for the suggestion Ryan but how can I can structure that?
0
pcelbaCommented:
The only single line command which can change data types of many columns in MySQL database is named mysqlimport. More info: http://webcheatsheet.com/sql/mysql_backup_restore.php

Everything else would need more lines. OTOH, single line does not mean better comfort or better results...
0
RotebergAuthor Commented:
Thanks Vikas!
But this is for all columns. so  how can i generate a query for  all tables or multiple tables ?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.