SQLite syntax: How to delete all records from table?

Pappsegull

Member
Licensed User
Longtime User
Hi,

I'm from sweden and did just buy this lovely software:icon_clap: so this is my first post.

I have start to play with it and I really enjoy:sign0060:

I did find those syntax to delete all records from a table here at w3schools:

DELETE FROM table_name

or

DELETE * FROM table_name

I have try both but get syntax error so I use to DROP and CREATE

DB.ExecNonQuery("DROP TABLE table_name")
DB.ExecNonQuery("CREATE TABLE table_name(Name TEXT, Value NUMERIC)")


Is there any other syntax to delete all records from a table?:confused:

Thanks!
 

Smee

Well-Known Member
Licensed User
Longtime User
This is the code i use to delete everything from a table and it works correctly

B4X:
SQLQry="DELETE FROM TableName"
SQL.ExecNonQuery(SQLQry)

Obviously you dont need to define the string first it is just one of my hangovers from using LONG Sql queries

Joe
 
Upvote 0

devlei

Active Member
Licensed User
Longtime User
I have limited experience, but also found some SQL (W3Schools) commands were different than for SQLite. The 2nd option (DELETE * FROM tablename) has always worked for me. If it is not working for you, there must be some other error on your side.
 
Upvote 0

Pappsegull

Member
Licensed User
Longtime User
Solved

Thank you, now it works:) I think the failure was due not to the table was in the database. Coz there was a old version on the device.

I don't know where to find the SQLite database on my C: drive that the AVD create! Anyone else that knows?
(DBDir = File.DirInternal: DBName = "sql_cc.db")

Now I have have found and added the error handler, which makes it easier to find the errors myself:)

Try

Catch

End Try


I guess I'm too eager to write code and do not like to read. :sign0144:
But there is so much fun that I, with my old VB3 - VB6 skills can start develop for Android. I'm too old and slow in the brain to learn a new programming language. :)

/Jan, Sweden
 
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
I guess I'm too eager to write code and do not like to read.
But there is so much fun that I, with my old VB3 - VB6 skills can start develop for Android. I'm too old and slow in the brain to learn a new programming language.

Join the club

A lot of us are exactly the same but it is still a lot of fun

:icon_clap::icon_clap:
 
Upvote 0
Top