Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)
I myself know that I can use an alter table individually to change the table storage from MyISAM to the InnoDB.

But I am thinking if there could be any way to quickly change all of them to InnoDB?

1 Answer

0 votes
by (12.7k points)

This following code will help you with that:

<?php
    // connect your database here first 
    // 

    // Actual code starts here 

    $sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
        WHERE TABLE_SCHEMA = 'your_database_name' 
        AND ENGINE = 'MyISAM'";

    $rs = mysql_query($sql);

    while($row = mysql_fetch_array($rs))
    {
        $tbl = $row[0];
        $sql = "ALTER TABLE `$tbl` ENGINE=INNODB";
        mysql_query($sql);
    }
?>

Are you interested to learn SQL in detail? Sign up for this perfect SQL Training course by Intellipaat.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 24, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
0 votes
1 answer
asked Jul 6, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
asked Jul 20, 2019 in SQL by Tech4ever (20.3k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...