用于提取 SQLite 表架构的 SQL 命令? [英] SQL command to extract schema of a SQLite table?

查看:25
本文介绍了用于提取 SQLite 表架构的 SQL 命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法决定这是否是一个愚蠢的问题,但我会冒险.:)

I can't decide if this is a dumb question or not but I'll take the risk. :)

我是一个相当简单的 SQL 用户 - 我了解 CREATE/DROP 表和 SELECT、INSERT、DELETE 的基本形式,但仅此而已.我想知道的是,是否可以通过 SQL 请求表的架构?

I'm a fairly simple SQL user - I understand CREATE/DROP tables and SELECT, INSERT, DELETE in their basic forms but not much more. What I'd like to know is if there's a way with SQL to request the schema of a table?

我有一个使用 SQLite 的 PC 应用程序,我正在为它编写一个移动客户端.我不需要 PC DB 中的所有表,也不需要表中的所有列.在 SQLite Spy 中,我可以右键单击一个表并选择显示 CREATE 语句",它会生成重新创建表所需的 SQL.

I have a PC app which uses SQLite and I'm writing a mobile client for it. I don't need all of the tables from the PC DB and not all columns from the tables. In SQLite Spy, I can right-click a table and select 'Show CREATE statement' which generates the SQL needed to recreate the table.

我想要做什么(使用 PC 上的代码)来获取我需要的 SQLite 表的 CREATE 语句(或至少是模式),然后编辑字符串以仅包含我需要的列.然后可以将这些传递给我的移动应用程序,以便它可以在设备上创建子集"数据库.可能吗?

What I'd like to do (using code on the PC) to get the CREATE statement (or at least the schema) of the SQLite tables I need and then edit the strings to include only the columns I need. These could then be passed to my mobile app so it could create the 'subset' DB on the device. Is it possible?

对于那些在我之后寻找类似答案的人.感谢 dan04 为我指明了正确的方向.使用结果...

For anyone who comes after me looking for a similar answer. Thanks to dan04 pointing me in the right direction. The results of using...

SELECT * FROM sqlite_master

... 包含一个名为sql"的列,其中包含 CREATE 语句.正是我要找的.:)

... include a column called 'sql' which includes the CREATE statement. Just what I'm looking for. :)

推荐答案

它存储在 sqlite_master 表中.

这篇关于用于提取 SQLite 表架构的 SQL 命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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