将表从 .sql 复制到 .db 文件.. 学习 SQL 的艰难方法 [英] Copying tables from a .sql to a .db file.. Learn SQL The Hard Way

查看:24
本文介绍了将表从 .sql 复制到 .db 文件.. 学习 SQL 的艰难方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很确定对此有一个简单的答案,但我无法在任何地方找到它,而且我自己似乎也无法弄清楚.. 任何帮助将不胜感激.

I'm pretty sure there is a simple answer to this but I can't find it anywhere and can't seem to figure it out for myself.. Any help would be greatly appreciated.

我正在尝试从包含基本表的 .sql 文件 (ex1.sql) 中复制一个表.我可以创建这个没问题,但是然后我运行以下命令将此表复制到数据库中 (ex1.db):

I'm trying to copy a table from a .sql file (ex1.sql) that has a basic table in it. I can create this no problem but then I'm running the following to copy this table into a database (ex1.db):

sqlite3 ex1.db < ex1.sql

我收到以下回复

C:\SQLite>sqlite3 ex1.db <ex1.sqlonperson CREATE TABLE person(格式 3) 注意:onperson"后的笑脸符号
名字文本,
姓氏文本,
年龄整数
)

C:\SQLite>sqlite3 ex1.db < ex1.sql onperson CREATE TABLE person (format 3) NB: smileyface symbol after "onperson"
first_name text,
last_name text,
age integer
)

看起来该表正在数据库中复制还是我弄错了?

It looks like the table is being replicated in the database or am I getting this wrong?

无论如何,当我回到 ex1.db 时,那里没有表.

Anyway, when I then go back into the ex1.db there is no table there.

知道为什么这不保存吗?我是否需要为此添加更多命令才能将其保存在 db 文件中?

Any idea as to why this isn't saving? Do I need to add further commands to this to get it to save in the db file?

如果这是一个愚蠢的问题,我深表歉意.对此相当陌生.

Apologies if this is a stupid question. Rather new to this.

谢谢!

推荐答案

我遇到了这个确切的问题,我以前从未接触过 SQLite.以下是对未来人们的更多说明.

I ran into this exact problem, and I have never touched SQLite before. Here are more instructions for people in the future.

在文本编辑器中,创建 ex1.sql.当命令 sqlite3 ex1.db < 时,这是将用于创建 .db 的文件.ex1.sql 运行.

In a text editor, create ex1.sql. This is the file that will be used to create the .db when the command sqlite3 ex1.db < ex1.sql is run.

ex1.sql

CREATE TABLE person (
    id INTEGER PRIMARY KEY,
    first_name TEXT,
    last_name TEXT,
    age INTEGER
);

确保将此文件保存在与您下载的 sqlite3.exe 文件相同的文件夹中.您现在可以运行上述命令,一切顺利!

Make sure to save this file in the same folder as the sqlite3.exe file you downloaded. You can now run the aforementioned command and you are good to go!

这篇关于将表从 .sql 复制到 .db 文件.. 学习 SQL 的艰难方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆