本文介绍了将表结构复制到sqlite3中的新表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以将现有的表结构复制到新的表结构?
(不需要数据,只需要结构->如id INTEGER,名称varchar(20)...)

Is there an easy way to copy an existing table structure to a new one?(dont need the data, only the structure -> like id INTEGER, name varchar(20) ...)

Thx

推荐答案

您可以使用以下命令:

CREATE TABLE copied AS SELECT * FROM mytable WHERE 0

但是由于SQLite的动态类型,大多数类型信息

but due to SQLite's dynamic typing, most type information would be lost.

如果您只需要一个行为与原始表相同的表,即具有相同的列号和名称,并且可以存储相同的值,则此

If you need just a table that behaves like the original, i.e., has the same number and names of columns, and can store the same values, this is enough.

如果您确实确实需要与原始信息完全一样的类型信息,则可以阅读原始SQL CREATE TABLE sqlite_master 表中的>语句,例如:

If you really need the type information exactly like the original, you can read the original SQL CREATE TABLE statement from the sqlite_master table, like this:

SELECT sql FROM sqlite_master WHERE type='table' AND name='mytable'

这篇关于将表结构复制到sqlite3中的新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 08:33