尽管DELETE
命令会起作用,但它很慢,因为它会选择每一行然后继续删除它。
如果您要删除整个表,最好使用DROP
该表而不是重新创建它:
BOOL result = [db executeUpdate:@"DROP TABLE IF EXISTS `customers`;"];
BOOL resultTwo = [db executeUpdate:@"CREATE TABLE IF NOT EXISTS customers(name text primary key, age int)"]; //or course fields in your table will be different
斯威夫特(为了完整起见):
let dropTable = "DROP TABLE customers"
let result = contactDB.executeUpdate(dropTable, withArgumentsInArray: nil)
if !result {
print("Error: \(contactDB.lastErrorMessage())")
}
let createTable = "CREATE TABLE IF NOT EXISTS customers(name text primary key, age int)"
if !contactDB.executeStatements(createTable) {
print("Error: \(contactDB.lastErrorMessage())")
}
参考:截断 SQLite