$link = mysql_connect('', '', ''); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db('-basededatos-', $link) or die('Could not select database: ' . mysql_error() ); $tables = mysql_query( 'SHOW TABLES' ); if (!$tables) { echo 'Could not run query: ' . mysql_error(); exit; } if (mysql_num_rows($tables) <= 0) { die; } while ($table = mysql_fetch_array( $tables ) ) { $columns = mysql_query( 'SHOW COLUMNS FROM `' . $table[ 0 ] . '` where Extra = "auto_increment"' ); if (!$columns) { echo 'Could not run query: ' . mysql_error(); die; } if (mysql_num_rows( $columns ) > 0) { while ( $col = mysql_fetch_assoc( $columns ) ) { echo sprintf( "ALTER TABLE `%s` CHANGE `%s` `%s` %s auto_increment;\n", $table[ 0 ], $col[ 'Field' ], $col[ 'Field' ], $col[ 'Type' ] ); } } } mysql_close($link);