2012-04-14 104 views
0

在SQLite(对于C#.NET)中是否存在执行此操作的SQL命令?从SQLite的所有表中删除

DELETE * FROM * WHERE id='idnumber'

+0

可能重复[Sqlite:如何重置所有数据库表?](http://stackoverflow.com/questions/3600075/sqlite-how-do-i-reset-all-database-tables) – 2012-04-14 13:58:35

+0

@juergend这个问题是关于删除所有表中的单个记录,而不是所有表中的所有记录。 – CJxD 2012-04-14 14:02:07

+0

不是不是。这完全不像。你应该在投票之前尝试阅读一个问题。 – 2012-04-14 14:04:30

回答

2

没有,有没有。

一种方法是编写一个脚本来query metadata tables创建另一个脚本一系列个人delete陈述,每桌之一。

一个例子可以(假设每有一个ID列):

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

这将产生对每个表,然后您可以捕获和运行的脚本delete声明。

但它通常是为数据库开发人员知道他们的表的名称:-)

+0

我知道这个名字,但是我有很多表= P 反正,这个'小脚本'怎么做? – CJxD 2012-04-14 14:00:26

+0

@CJxD,我添加了一个小片段,希望这是一个很好的起点。这是未经测试的,但你应该明白。 – paxdiablo 2012-04-14 14:08:19

+2

看起来很狡猾,我喜欢它! – CJxD 2012-04-14 14:23:41

-1

你可以尝试使用它是一个好主意:

//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; 

希望这将是对你有用。

+2

这将删除表格,是吗?我认为OP只是想删除所有表中具有匹配ID的所有行。所以可能不会_that_有用:-) – paxdiablo 2012-04-14 14:02:08

+0

这是你的博客吗? http://myratnest.blogspot.com/2010/08/want-to-delete-all-tables-in-sqlite.html – 2012-04-14 14:30:19

+0

或你的答案? http://stackoverflow.com/questions/525512/drop-all-tables-command – 2012-04-14 14:31:04