这段代码将在以下位置创建数据库:LocalFolder
string DBPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "customers.sqlite");
using (var db = new SQLite.SQLiteConnection(DBPath))
{
// Create the tables if they don't exist
db.CreateTable<Customer>();
db.CreateTable<Item>();
}
问题:
一旦以前使用过每个表,下面的代码将不会将每个表的主键重置为0(或起始编号)。此代码是否仅清空表,而不重置主键?
如何删除customers.sqlite(创建数据库),以便将所有主键重置为起始编号,如0。
using (var db = new SQLite.SQLiteConnection(DBPath))
{
db.DeleteAll<Customer>();
db.DeleteAll<Item>();
}
最佳答案
通过此查询,您可以清除表格,然后重置自动递增列。
using (var db = new SQLiteConnection(ApplicationData.Current.LocalFolder.Path + "\\db.sqlite"))
{
db.Query<your_table_name>("delete from your_table_name", "");
db.Query<sqlite_sequence>("delete from sqlite_sequence where name = ?", "your_table_name");
}
您还必须添加此类。
public class sqlite_sequence
{
public string name { get; set; }
public int seq { get; set; }
}
关于sqlite - 如何重置主键并删除创建的SQLite Db,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19269547/