On 6 Jun 2012, at 12:42pm, vallur raghava reddy <vallur.raghavare...@gmail.com> wrote:
> I have created a database "MyDb.db" and created a table MyTable using > the query *create table MyTable (id INTEGER PRIMARY KEY, value > CHARACTER(10))* and inserted 3000 records in the table.I executed query > *select > * from MyTable* it returned 3000 rows and was able to print all values. > Now the size of the db file MyDB.db is 57kb. > After that I have deleted all the records and then I executed query *select > * from MyTable* it returned zero rows. > Now I have checked file size and it is same as 57kb. > So my question is, why does the file size is not decreased after deleting > the rows? Thank you for your clear description of your experiment, which made it easy to understand your question. SQLite doesn't return unused space to the file system unless you ask it to. It takes a lot of time to make the space available for other files, and more time to steal the space back again the next time it's needed. Faster just to hog that space until it's needed again: keep it in the database file, marked as unused. But you can force SQLite to give up that space using the VACUUM command. Try executing VACUUM after your DELETE FROM command and your file should shrink as you expected. <http://www.sqlite.org/lang_vacuum.html> This is useful while you're checking that you understand how SQLite works, but in real application you code you would probably never use VACUUM unless routine use of your app often deletes a lot of data without immediately reusing the space. A short note while I'm here: you used a column type of CHARACTER(10) which shows you've been using other implementations of SQL. This will get results under SQLite, but it may not do exactly what you expect. You may find it useful to sometime read <http://www.sqlite.org/datatype3.html> Simon. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users