1,105,340 Community Members

how to empty database tables

Member Avatar
nakresimin
Light Poster
40 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

is it possible to empty all the tables in the database without dropping them with shell script?
if yes could you please show me?

thank you

Member Avatar
L7Sqr
Veteran Poster
1,006 posts since Feb 2011
Reputation Points: 179 [?]
Q&As Helped to Solve: 168 [?]
Skill Endorsements: 11 [?]
 
0
 

If you want to empty the tables of a database you are going to, at some point, use the facilities provided by the database designers to do so. This may be a command line script to drop tables or a program that uses the database API to do it programatically.
Short of deleting all of the database files on the system there isn't much of an alternative.

Member Avatar
JeoSaurus
Posting Whiz in Training
227 posts since Sep 2008
Reputation Points: 32 [?]
Q&As Helped to Solve: 36 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi nakresimin!

What kind of database? MySQL has a command line utility that allows you to execute database commands from a shell script. For instance, to delete all the rows in a table called bartable, in a database called dbfoo:

mysql dbfoo -e 'delete from bartable'

Of course, you'll need to have a .my.cnf file with login credentials for that database OR provide the username and password to the mysql command (mysql -uuser -ppass dbfoo ...).

That's all I've got!

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article