0

SQLite(用于 C#.NET)中是否有执行等效操作的 SQL 命令?

DELETE * FROM * WHERE id='idnumber'

4

4 回答 4

4

不,没有。

一种方法是编写一个小脚本来查询元数据表,以创建另一个脚本,其中包含一系列单独的delete语句,每个表一个。

一个例子可能是(假设每个表都有一个 ID 列):

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

这将为delete每个表生成一个语句,然后您可以将其捕获并作为脚本运行。

但是对于数据库开发人员来说,知道他们的表的名称通常是一个好主意:-)

于 2012-04-14T13:58:55.903 回答
0

此删除将擦除数据库中的所有内容:

.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

请注意,如果您忽略它,WHERE id="idnumber"这将清除您的数据库!

于 2020-01-06T07:47:43.190 回答
0

我用于动态编程目的的一种方法是创建一个表名数组并循环遍历它们。

例如

迅速

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

for item in array

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

//run the command on the database

}

我希望这可以帮助别人。非常适合诸如注销或清除搜索数据之类的事情。您甚至可以扩展数组并将其作为函数调用。

于 2021-09-17T18:40:30.893 回答
-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;

希望它对你有用。

于 2012-04-14T14:01:15.513 回答