Gossamer Forum
Home : General : Databases and SQL :

Lower case to upper...

Quote Reply
Lower case to upper...
Is there any way I can change the name of a table. At the moment I have tables like;

links_something
links_category
links_rubbish

Is there any way, or script, that you could rename the tables to have capitals in the second palf of it (i.e after the _). Like this;

links_Something
links_Category
links_Rubbish

I'm assuming it could be done by grabbing the list of tables in the database, and then splitting thgem up by the _. Then capitalising the second half. However, I'm not very good with Perl and SQL...so any help you an offer would be appreciated Smile

Thanks

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Lower case to upper... In reply to
http://www.mysql.com/.../E/RENAME_TABLE.html

get the table names via dbi and use the regex

$loc = index($name, "_") + 1;
$replaced = substr($name, $loc);
$name = $name . ucfirst($replaced);
$sth = $sth->prepare("rename table $beforename TO $name");
$sth->execute();

Some of that is a bit poor, but I would appreciate it if anyone could give me ideas on how to improve that.
------------------
Dorg Hurgler Van Schongleur,
NordHein Van Resetelem, Belgium.
Eck SchekeBuugler Technologies.

Last edited by:

searchposts: Jun 3, 2002, 10:41 AM
Quote Reply
Re: [searchposts] Lower case to upper... In reply to
and for the table listings you could use show tables;

you will need the error checking too obviously
------------------
Dorg Hurgler Van Schongleur,
NordHein Van Resetelem, Belgium.
Eck SchekeBuugler Technologies.