Solved

Add prefix to tables in MySQL database?

Posted on 2008-06-18
3
1,854 Views
Last Modified: 2013-12-12
Hi,

Is there a way to add a prefix to all existing tables in a MySQL database? Lets say I want to add the prefix 'abc' in front of each table name in the database.
0
Comment
Question by:fcruz5
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 21817348
you can rename a table in MySQL:
http://dev.mysql.com/doc/refman/5.0/en/alter-table.html
ALTER TABLE tablename RENAME TO new_tablename;

so, as you posted in php, all you have to do is to get the list of the tables:
SHOW TABLES

and for each table run the above ALTER TABLE statement, filling in the table names...
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 500 total points
ID: 21817362
quick and dirty php code:
<?php
  // connect code ... 
  mysql_connect( ... ); 
  // fetch table listing
  $rows = mysql_query("SHOW TABLES");
  while ($row = mysql_fetch_array($rows"))
  {
    $table_name = $row[0];
    mysql_query("ALTER TABLE $table_name RENAME TO abc$table_name "); 
  } 
?>

Open in new window

0
 

Author Closing Comment

by:fcruz5
ID: 31468585
Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

689 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question