SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2005
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to Batch Rename Tables?

    I have a few Wordpress databases that need to have the tables renamed. I would like to make a script to batch process this.

    Currently the databases have names like this:

    wp_j1rry4_comments
    wp_j1rry4_links
    wp_j1rry4_options
    wp_j1rry4_postmeta
    wp_j1rry4_posts
    wp_j1rry4_terms
    wp_j1rry4_term_relationships
    wp_j1rry4_term_taxonomy
    wp_j1rry4_usermeta
    wp_j1rry4_users


    How could I change them to have their names like this:

    wp_comments
    wp_links
    wp_options
    wp_postmeta
    wp_posts
    wp_terms
    wp_term_relationships
    wp_term_taxonomy
    wp_usermeta
    wp_users

    I found this webpage that does something similar but they are adding a prefix to the table name, I want to take characters away.
    Domain Name Coupon Codes for popular registers
    Web Hosting Coupon Codes save on website hosting

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,250
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Code:
    RENAME TABLE
      wp_j1rry4_comments            TO wp_comments
    , wp_j1rry4_links               TO wp_links
    , wp_j1rry4_options             TO wp_options
    , wp_j1rry4_postmeta            TO wp_postmeta
    , wp_j1rry4_posts               TO wp_posts
    , wp_j1rry4_terms               TO wp_terms
    , wp_j1rry4_term_relationships  TO wp_term_relationships
    , wp_j1rry4_term_taxonomy       TO wp_term_taxonomy
    , wp_j1rry4_usermeta            TO wp_usermeta
    , wp_j1rry4_users               TO wp_users
    ;
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2005
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks very much r937, you made it look easy
    Domain Name Coupon Codes for popular registers
    Web Hosting Coupon Codes save on website hosting


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
  •