如何从sqlite中的另一个数据库导入表? [英] How do I import tables from another database in sqlite?

查看:16
本文介绍了如何从sqlite中的另一个数据库导入表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有名为 database1 的 SQLite 数据库,带有一个表 t1database2 带有一个表 t2.我想将表 t2database2 导入 database1.我应该使用什么命令?

I have SQLite databases named database1 with a table t1 and database2 with a table t2. I want to import table t2 from database2 into database1. What command(s) should I use?

推荐答案

使用 sqlite3 命令行工具 并使用命令 .schema t2 读取表定义.(或者,使用任何其他允许读取表定义的工具.)

Open database2 with the sqlite3 command-line tool and read the table definition with the command .schema t2. (Alternatively, use any other tool that allows to read the table definition.)

然后打开database1,用命令attach另一个数据库:

Then open database1, attach the other database with the command:

ATTACH 'database2file' AS db2;

然后创建表t2,并将数据复制过来:

then create the table t2, and copy the data over with:

INSERT INTO t2 SELECT * FROM db2.t2;

这篇关于如何从sqlite中的另一个数据库导入表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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