Deleting all records in a table

This is a discussion on Deleting all records in a table within the MySQL Database forums, part of the Database Forums category; How do I delete all records in a table instead of having to iterate through all the data using Python ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-21-2007
Vernon Wenberg III
 
Posts: n/a
Default Deleting all records in a table

How do I delete all records in a table instead of having to iterate
through all the data using Python and deleting by ID?
Reply With Quote
  #2 (permalink)  
Old 12-21-2007
J.O. Aho
 
Posts: n/a
Default Re: Deleting all records in a table

Vernon Wenberg III wrote:
> How do I delete all records in a table instead of having to iterate
> through all the data using Python and deleting by ID?


DELETE FROM table

--

//Aho
Reply With Quote
  #3 (permalink)  
Old 12-22-2007
strawberry
 
Posts: n/a
Default Re: Deleting all records in a table

On Dec 21, 10:35 pm, "J.O. Aho" <u...@example.net> wrote:
> Vernon Wenberg III wrote:
> > How do I delete all records in a table instead of having to iterate
> > through all the data using Python and deleting by ID?

>
> DELETE FROM table
>
> --
>
> //Aho


Or just drop the table and then recreate it (minus the data).
Reply With Quote
  #4 (permalink)  
Old 12-22-2007
Evan Keel
 
Posts: n/a
Default Re: Deleting all records in a table


"Vernon Wenberg III" <vwenberg@gmail.com> wrote in message
news:K9Xaj.262440$Fc.252453@attbi_s21...
> How do I delete all records in a table instead of having to iterate
> through all the data using Python and deleting by ID?


Here is the "standard" way.

http://dev.mysql.com/doc/refman/5.0/en/truncate.html


Reply With Quote
  #5 (permalink)  
Old 12-22-2007
Kees Nuyt
 
Posts: n/a
Default Re: Deleting all records in a table

On Sat, 22 Dec 2007 13:16:17 GMT, "Evan Keel"
<evankeel@sbcglobal.net> wrote:

>
>"Vernon Wenberg III" <vwenberg@gmail.com> wrote in message
>news:K9Xaj.262440$Fc.252453@attbi_s21...
>> How do I delete all records in a table instead of having to iterate
>> through all the data using Python and deleting by ID?

>
>Here is the "standard" way.
>
>http://dev.mysql.com/doc/refman/5.0/en/truncate.html


I'm very glad you "quoted" the word standard, because
TRUNCATE is not very standard in relational database
theory (and SQL).

For example, ON DELETE triggers aren't invoked, and
auto_increment counters are reset. That can easily ruin
the integrity of a database. So, TRUNCATE is potentially
very dangerous.

I would consider it more a DBA tool than a programming
statement, only to be used by experts. That's also the
place it has in the SQL99 standard and in PostgreSQL.

Though slower, the real standard way is DELETE FROM
tablename;
--
( Kees
)
c[_] Giving power and money to government is like giving
whiskey and car-keys to teenage boys. (PJ O'Rourke) (#181)
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:13 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0