empty tables

Peperl
04-14-2004, 03:19 PM
Hi

Working with MySQL sometimes I need to empty a table, what i do it's a bucle and erase all the fields one by one.

Is there a way to empty a table like in MySQL-Front? or another faster method?

Thanks very much!

MKoslof
04-14-2004, 03:21 PM
Use the Delete SQL Syntax:



"DELETE FROM myTable WHERE Field1 = 'mkoslof'"



This will delete all records from the table where field1 equals MKoslof, or you could delete all records, etc.

CrystalWizard
04-14-2004, 03:39 PM
This might be a bit quicker

TRUNCATE TABLE differs from DELETE FROM ... in the following ways:

Truncate operations drop and re-create the table, which is much faster than deleting rows one by one.
Truncate operations are not transaction-safe; you will get an error if you have an active transaction or an active table lock.
The number of deleted rows is not returned.
As long as the table definition file `tbl_name.frm' is valid, the table can be re-created this way, even if the data or index files have become corrupted.
The table handler might not remember the last used AUTO_INCREMENT value but may start counting from the beginning. This is true for MyISAM, ISAM, and BDB tables.

From...
http://dev.mysql.com/doc/mysql/en/TRUNCATE.html

Peperl
04-14-2004, 05:01 PM
I put the DELETE FROM table method and seems to works fine

Thanks to both

MKoslof
04-14-2004, 05:54 PM
I don't think TRUNCATE is quicker then DELETE FROM. It might be slightly, but the difference is negliable. Glad you got it working. Good luck.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum