title: MySQL Alter Table Change all fields type using wild card?
body: <p>I am creating a new table by copying an existing table structure:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `PeopleView` LIKE `People`
  </code></pre>
  
  <p>I then want to change the data type of all fields using a wild card:</p>
  
  <pre><code>ALTER TABLE `PeopleView` CHANGE * * VARCHAR(3) NOT NULL
  </code></pre>
  
  <p><strong>Any ideas how to do this?</strong></p>
  
  <p>I can do something like:</p>
  
  <pre><code>ALTER TABLE `PeopleView` CHANGE `FirstName` `FirstName` VARCHAR(3) NOT NULL
  </code></pre>
  
  <p>But I need a function I can run on many different tables where the field names are all different.</p>
  
  <p>Purpose: Create another table that holds values that are used to decide which columns will be shown or hidden.</p>
  
  <p><strong>PHP Solution:</strong></p>
  
  <pre><code>mysql_query("CREATE TABLE IF NOT EXISTS `PeopleView` LIKE `People`");
  
  $cols = mysql_query("SHOW COLUMNS FROM `PeopleView`");
  
  $sql = "ALTER TABLE `PeopleView` ";
  while($row = mysql_fetch_assoc($cols)) {
    $sql .= "MODIFY `". $row['Field'] ."` VARCHAR(3) NOT NULL, ";
  }
  $sql = substr($sql, 0, -2);
  mysql_query($sql);
  </code></pre>
  
  <p><strong>I don't like that I have to run 3 queries to the database, surely there is a better way?</strong></p>