We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

how to empty database tables

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

3
Contributors
2
Replies
1 Week
Discussion Span
1 Year Ago
Last Updated
3
Views
nakresimin
Light Poster
40 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

L7Sqr
Practically a Posting Shark
851 posts since Feb 2011
Reputation Points: 253
Solved Threads: 155
Skill Endorsements: 7

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!

Gromit
Posting Whiz in Training
224 posts since Sep 2008
Reputation Points: 50
Solved Threads: 34
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0553 seconds using 2.64MB