【问题标题】:Reading a file.sql and create the database读取 file.sql 并创建数据库
【发布时间】:2012-06-09 18:35:22
【问题描述】:

我有一个名为 schema.sql 的文件,它看起来像这样:

drop table if exists codes;
create table paste_codes (
    id integer primary key autoincrement,
    codetitle string not null,
    codebody string not null,
    pub_date string not null
)

有什么方法可以让 sqlite3 从这个文件中读取它并为我创建数据库? 像 cat schema.sql > sqlite3 /tmp/database.db 之类的东西?

谢谢

【问题讨论】:

  • 请注意:SQL 文件指示创建表,而不是数据库。有很大的不同。
  • 可能想看看stackoverflow.com/questions/489277/…(不知道更简单的方法)
  • 哦,我认为一个简单的管道方式就可以完成这项工作,一个完整的 sh 代码!谢谢小伙伴们!西蒙,谢谢,我会好好看看!

标签: linux sqlite


【解决方案1】:

我解决了这个问题。 我将代码更改为:

drop table if exists paste_code;
create table paste_code (
    id integer primary key autoincrement,
    codetitle string not null,
    codebody string not null,
    pub_date string not null
);

我只是:

$ sqlite3 /tmp/database.db < schema.sql

一切都开始完美!

【讨论】:

    猜你喜欢
    • 2017-03-26
    • 2021-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-21
    • 2017-01-25
    • 1970-01-01
    相关资源
    最近更新 更多