|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Drop multiple tables based on table name?
I have about 30 or 40 tables all starting with a name prefix. Is there a way to drop all of these tables easily (mysql 4)?
|
|
#2
|
||||
|
||||
|
This should make you think, the right way of grouping tables is putting them in a specific database, not using a prefix.
__________________
My blog Tutorials about OSS databases, DBMonster ... Contribute to OSS Development, fill bug reports! Developer Shed eSupport Commented my.ini/my.cnf (ADD YOUR OWN CONFIG TRICK) An introduction to database normalization Natural or Surrogate key Custom ordering for your results Correlated and uncorrelated subqueries Don't turn your outer joins into inner joins Random data (with a bias) |
|
#3
|
|||
|
|||
|
I understand this, but up till about a year ago, godaddy.com only allowed one database (as apposed to now allowing 10 dbs). So to install multiple apps, a prefix is required.
So now, I'm stuck with a ton of tables with prefixes and am attempting to rebuild the server. Is there a way to delete multiple tables with the same prefix? |
|
#4
|
|||
|
|||
|
Ended up modding a script i found into two different scripts...
drop_tables.php - drops all tables with specified prefix drop_tables_reverse.php - drops all tables that do not have specified prefix (very dangerous if not used correctly!) Only db server, username, password, and database need to be changed in each script. (I guess sometimes you just have to take a problem into your own hand - but seperate dbs for each web app is the best option if available) --------------------------------------------------- DROP_TABLES.PHP --------------------------------------------------- PHP Code:
---------------------------------------------- DROP_TABLES_REVERSE.PHP ---------------------------------------------- PHP Code:
|
|
#6
|
|||
|
|||
|
I'm not sure what you are telling me here...I have the same situation as the guy in the other post. The guy ended up using exactly the kind of script I made. I too have access to a cut down version of phpmysql and do not have direct access to the server.
Trust me, for this situation, it is so much easier to use the script and not have to worry about being an SQL master. I understand the SQL commands that they put together, but unless you have access to an SQL command line or will create a different PHP script to do the command for you... |
|
#7
|
||||
|
||||
|
you should modify your scripts to use mysql_real_escape_string() without it you are vulnerable to sql injection attacks that could drop all the tables in your database.
__________________
MySQL - reformat varchar dates to proper date type || MySQL - room vacancies || output results with column names with mysql only Latest row per group || Deleting duplicates || Gaps in auto increment column My site: sql help articles |
|
#8
|
|||
|
|||
|
This script is not a permanent script for a site. It should only be used temporarily. Even with the function you specified, just executing the reverse script with any arbitrary prefix would remove every table in a database!
So what would be the sense in making the script more secure if the basic functionality would allow the same thing? ![]() |
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > Drop multiple tables based on table name? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|