sqlite3:使用drop表删除

时间:2017-06-29 10:31:15

标签: sqlite

我尝试使用sqlite3转储sqlite数据库:

sqlite3 example.sq3 .dump > backup.sql

这是一个示例输出:

PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS "articles" (
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
"author_id" INTEGER,
"title" VARCHAR,
"body" TEXT,
"published" VARCHAR(1) DEFAULT 'N'
);
INSERT INTO "articles" VALUES(1,1,'First Article','First Article Body','Y');
INSERT INTO "articles" VALUES(2,3,'Second Article','Second Article Body','Y');
INSERT INTO "articles" VALUES(3,1,'Third Article','Third Article Body','Y');
CREATE TABLE IF NOT EXISTS "comments" (
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
"article_id" INTEGER NOT NULL,
"user_id" INTEGER NOT NULL,
"comment" TEXT,
"published" VARCHAR(1) DEFAULT 'N',
"created" DATETIME,
"updated" DATETIME
);
INSERT INTO "comments" VALUES(1,1,2,'First Comment for First Article','Y','2007-03-18 10:45:23','2007-03-18 10:47:31');
INSERT INTO "comments" VALUES(2,1,4,'Second Comment for First Article','Y','2007-03-18 10:47:23','2007-03-18 10:49:31');
INSERT INTO "comments" VALUES(3,1,1,'Third Comment for First Article','Y','2007-03-18 10:49:23','2007-03-18 10:51:31');
INSERT INTO "comments" VALUES(4,1,1,'Fourth Comment for First Article','N','2007-03-18 10:51:23','2007-03-18 10:53:31');
INSERT INTO "comments" VALUES(5,2,1,'First Comment for Second Article','Y','2007-03-18 10:53:23','2007-03-18 10:55:31');
INSERT INTO "comments" VALUES(6,2,2,'Second Comment for Second Article','Y','2007-03-18 10:55:23','2007-03-18 10:57:31');
DELETE FROM sqlite_sequence;
INSERT INTO "sqlite_sequence" VALUES('articles',3);
INSERT INTO "sqlite_sequence" VALUES('comments',6);
COMMIT;

我的问题是表方案的转储总是使用语句CREATE TABLE IF NOT EXISTS,而我想删除现有表,因为当我导入转储时我可以不要物理擦除具有相同现有表和记录的现有数据库。

我检查了sqlite3命令选项,但我没有发现任何有用的信息。

我该怎么办?

1 个答案:

答案 0 :(得分:0)

sqlite3命令行shell中没有这样的选项。

您必须创建自己的转储工具,或编写脚本来调整SQL输出。