0

Is there a SQL command in SQLite (for C#.NET) which performs the equivalent of this?

DELETE * FROM * WHERE id='idnumber'

Chris Watts
  • 6,197
  • 7
  • 49
  • 98
  • possible duplicate of [Sqlite: How do I reset all database tables?](http://stackoverflow.com/questions/3600075/sqlite-how-do-i-reset-all-database-tables) – juergen d Apr 14 '12 at 13:58
  • @juergend This question is about deleting a single record from all tables rather than all records from all tables. – Chris Watts Apr 14 '12 at 14:02

4 Answers4

4

No, there's not.

One way is to write a little script to query metadata tables to create another script with a series of individual delete statements, one per table.

An example could be (assuming every table had an ID column):

select 'delete from ' || name || ' where ID = 42'
from sqlite_master
where type = 'table'

This would generate a delete statement for each table which you could then capture and run as a script.

But it's generally a good idea for database developers to know the names of their tables :-)

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
0

This remove will wipe all content from your database:

.output wipe.sql
.print BEGIN TRANSACTION;
SELECT 'DELETE FROM ' || name || ' WHERE id="idnumber";'
FROM sqlite_master
WHERE type = 'table';
.print COMMIT;
.print VACUUM;
.output
-- .read wipe.sql

Beware that if you leave out the WHERE id="idnumber" this will wipe your database!

0

A method that I use for dynamic programmatic purposes is creating an array of the table names and loop through them.

e.g.

Swift

var array = ['table1','table2','table3']

for item in array

{
    
var stringToDeleteTables:String = "DELETE FROM \\(item) [optional where clause]"

//run the command on the database

}

I hope this helps someone. Great for things such as sign outs or clearing search data. You can even make an extension of an array and call it as a function.

gbeaven
  • 1,522
  • 2
  • 20
  • 40
-1

You can use try it :

//You can do it with the following DANGEROUS commands:

PRAGMA writable_schema = 1;
delete from sqlite_master where type = 'table';
PRAGMA writable_schema = 0;



 //you then want to recover the deleted space with
 VACUUM

//and a good test to make sure everything is ok
 PRAGMA INTEGRITY_CHECK;

Hope it will be useful for you.

secretlm
  • 2,361
  • 2
  • 27
  • 38
  • 2
    That's going to delete the tables, yes? I think the OP just wants to delete all rows with a matching ID from all tables. So probably not _that_ useful :-) – paxdiablo Apr 14 '12 at 14:02