|
Answer» Hi,
I am in the middle of writing a DOS batch file that will be used to loop through all databases on a server and then loop through all tables in a database to truncate them.
So far I have:
@echo off :: prevent any of the commands in the batch file from being displayed
mysql -U DBusername -P DBpassword :: connect to database
sp_databases :: Lists databases on server
use databaseName :: say which database to use
show tables :: List all tables in database
FOR %%A IN (table1, table2, table3, table4) DO ( :: Loop thru tables
TRUNCATE TABLE %%A :: delete all data from table
)
EXIT
I have never used DOS before and have searched all over the internet to peice together the above and am now struggling on how I would loop through the results from the "Show tables" results. I have read that DOS does not support arrays and could only loop through a list.
Can anyone help with how I would exactly do this?
Many thanks in advancefirst off, what OS are you using?and what is your output from show tablesIts windows.
I dont know the results of show results. I have not been able to actually test this on the server yet, I am just trying to research how it will be done before I test it ont he server.unfortunately everything past
"mysql -U DBusername -P DBpassword :: connect to database"
is a SQL command. and will not work.
Instead you should be creating a stored procedure within mySQL, and calling that via the mysql command line.I have no idea what that means. I am a PHP / MySQL developer and have never worked with any of this before. I don't know either- my experience is with a FULL blown SQL server implementation.
I would guess that you would need to run the "mySQL" program, assuming it exists, with arguments DESCRIBING the commands you have following. You MIGHT need to check out the documentation for mySQL and determine what you can give to the program to make it execute one of your commands.ok thanks for your help.
|