SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast geeOff's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta, GA 30328
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    alter * ( all tables) ???

    does anyone know if there is a way to alter all tables in a DB ? i want to rename all the "partial" columns to "part_credit" like so:

    PHP Code:
    ALTER TABLE `grades`.`u10s2CHANGE `partial` `part_creditTINYINT(4) DEFAULT '0' NOT NULL 
    it seems that the word 'partial' is a reserved word with mySQL.

    Geoff

  2. #2
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nope, i don't think there is. you'll have to do each manually.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  3. #3
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Best solution would to try and run it through a loop to save you having to manually change each.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  4. #4
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: alter * ( all tables) ???

    Originally posted by geeOff
    it seems that the word 'partial' is a reserved word with mySQL.
    Yes it is.

    In pseudo php code, this is what Defender is suggesting,
    PHP Code:
    <?
    $tables 
    get_all_tables('yourdatabase');

    foreach (
    $tables as $table) {

     
    $sql "ALTER TABLE $table CHANGE `partial` `part_credit` TINYINT(4) DEFAULT '0' NOT NULL";

     
    mysql_query($sql);
    }
    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •