Search:
Main Menu
Login | RSS |

Quick PHP Code Tips and Examples

PHP Programming Tips, Tutorials and Source Code Examples for newbie

How to Truncate table in SQLite database

June 4th, 2008 by Jon Moffet

I found out that truncating SQLite database is a little bit different from its MySQL counterpart. Here's how to truncate SQLite database from command line

CODE:
  1. sqlite your_database.db
  2. sqlite> DELETE FROM some_table;

after that, dont forget to execute VACUUM to compact the database :

CODE:
  1. sqlite> VACUUM;

Bookmark Post:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • NewsVine
  • Reddit
  • Netvouz
  • Spurl
  • Furl
  • digg
  • YahooMyWeb
  • del.icio.us

Posted in Uncategorized |

Related Posts

7 Responses

  1. Pushpesh Says:

    This took me almost a day to figure out that “TRUNCATE” won’t work in sqlite!…thanks :)

    hope somebody else finds it helpful!

  2. PP Says:

    Very important tip: if your table has primary key has AUTOINCREMENT when table is created, SQLITE will behave differently and DELETE FROM tablename; will NOT reset row id to initial value. Because if AUTOINCREMENT is set, SQLite uses different algorithm for calculating auto-increment value so the above won’t work.

  3. PP Says:

    I suggest you update main text with this tip.

  4. Need help for SQLite Says:

    [...] in SQLite!! no other go we have to use delete….. For further reference check this link : How to Truncate table in SQLite database » Quick PHP Code Tips and Examples -Arvind "Hacking isn’t spreading viruses or causing damage to other computer systems. It [...]

  5. Cristine Pauley Says:

    Discovered your blog whilst I was browsing for knowledge for our web site, obviously it’s not all releative however it is funny how you can reach a site by chance and discover yourself looking through something totally different but just as worthwhile. I am inclined to get distracted a multiple times doing this.

  6. database - can we use truncate query in android sqlite - Stack Overflow Says:

    Kramer auto Pingback[...] source: http://phpcode.mypapit.net/how-to-truncate-table-in-sqlite-database/49/ [...]

  7. Prasildas Says:

    Hi,
    Is there a way we can truncate the table in SQLite .

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.