473,394 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Bulk Rename - Best Practices?

Howdy, All,

Was trying to modify all tables in a particular database starting with
the same prefix, i.e., "tbl_".

Decided I'd rather have them all start with "_tbl_" instead.

Being lazy, didn't want to rename them one at a time.

Finally:

1) Went into phpMyAdmin's SQL window.

2) Ran "show tables like 'tbl_%';"

3) Copied the resulting column into my text editor.

4) Fiddled with regex search / replace & a tiny macro to create
"rename table tbl_mytable to _tbl_mytable"
and so on, one table per line.

5) Ran that file as source in a CLI session.

So, they're renamed. But am just curious if there was a more direct
way, rather than having to suck all the names in & massage a source file.

AFAIK, RENAME does not support wildcards, which is where I got stuck.

So, the question is: Was there a way to have done this entirely within
MySQL (i.e., with one statement), as opposed to the method I used?

Thanks!
--
Carl
Jan 16 '07 #1
1 6995
Carl Pearson wrote:
Howdy, All,

Was trying to modify all tables in a particular database starting with
the same prefix, i.e., "tbl_".

Decided I'd rather have them all start with "_tbl_" instead.

Being lazy, didn't want to rename them one at a time.

Finally:

1) Went into phpMyAdmin's SQL window.

2) Ran "show tables like 'tbl_%';"

3) Copied the resulting column into my text editor.

4) Fiddled with regex search / replace & a tiny macro to create
"rename table tbl_mytable to _tbl_mytable"
and so on, one table per line.

5) Ran that file as source in a CLI session.

So, they're renamed. But am just curious if there was a more direct
way, rather than having to suck all the names in & massage a source file.

AFAIK, RENAME does not support wildcards, which is where I got stuck.

So, the question is: Was there a way to have done this entirely within
MySQL (i.e., with one statement), as opposed to the method I used?

Thanks!
--
Carl

This will create output that can be executed.
mysqlselect 'rename table '
||table_schema||'.'||table_name
||' to '||table_schema||'._'||table_name';'
as runthis
from information_schema.tables
where table_name like 'tbl%';
+-------------------------------------------------+
| runthis |
+-------------------------------------------------+
| rename table mysql.tbl_test to mysql._tbl_test; |
+-------------------------------------------------+

the double pipe is the ANSI standard for concatenate. I suppose you could write
this with CONCAT(), but I prefer this way...

of course you can then take the output - remove the "|" and paste it back into
your session. I am sure there are other ways, this is just off the top...
--
Michael Austin
Database Consultant
Domain Registration and Linux/Windows Web Hosting Reseller
http://www.spacelots.com
Jan 19 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris | last post by:
Any help would be appreciated. I am running a script that does the following in succession. 1-Drop existing database and create new database 2-Defines tables, stored procedures and functions...
2
by: Steve_CA | last post by:
Hello all, I just started a new job this week and they complain about the length of time it takes to load data into their data warehouse, which they do once a month. From what I can gather,...
2
by: byrocat | last post by:
I'm chasing after a documetn that was available on one of the Microsoft websites that was titled somethign like "MS SQL Server Best Practices" and detailed a nyumber of best practices about...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
13
by: john doe | last post by:
A quick question, about so-called 'best practices', I'm interested in which of A/B of the two examples people would choose, and why. public enum MyEnum { Option1 = 0, Option2 = 1, Option3 =...
2
by: Amelyan | last post by:
Could anyone recommend a book (or a web site) that defines best practices in ASP.NET application development? E.g. 1) Precede your control id's with type of control btnSubmit, txtName, etc. 2)...
10
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read...
2
by: Zarrin | last post by:
Hello, I read several articles of newsgroup about the bulk delete, and I found one way is to: -create a temporary table with all constraints of original table -insert rows to be retained into...
3
by: John Dalberg | last post by:
I am looking for an ASP.NET application on CodePlex which exemplifies best practices for the following: - Use of interfaces - Seperation of the UI, business and data tiers - Data Tier that uses...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.