Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在数据库中的表本身上创建索引?_Python_Sqlite - Fatal编程技术网

Python 如何在数据库中的表本身上创建索引?

Python 如何在数据库中的表本身上创建索引?,python,sqlite,Python,Sqlite,我用python包装我的SQL代码,如下所示: connection=apsw.Connection("dbfile"); cursor=connection.cursor() cursor.execute("create table foo(x,y,z)") cursor.execute("create table bar(a,b,c)") cursor.execute("create table baz(one,two,three)") 我计划使用gui框架来显示这些表名(以及随后的列和行

我用python包装我的SQL代码,如下所示:

connection=apsw.Connection("dbfile"); cursor=connection.cursor()
cursor.execute("create table foo(x,y,z)")
cursor.execute("create table bar(a,b,c)")
cursor.execute("create table baz(one,two,three)")
我计划使用gui框架来显示这些表名(以及随后的列和行)。我还想按照不同的标准对这些表名进行排序

有没有办法在表本身上创建一个用于排序的索引?例如:

提前感谢。

在sqlite数据库中使用

cursor.execute(
    "SELECT tbl_name FROM sqlite_master WHERE type='table'")

table_names = cursor.fetchall()

一旦有了表名,就可以使用字符串格式来形成
创建索引
命令。

除了@unutbu answer,还可以:


它返回单个表的信息。

许多数据库都包含您在其模式目录中已经查找到的元数据。了解您试图使用的确切数据库可能有助于我们引导您找到这些目录的文档;或者,如果您想要一个跨数据库的解决方案,请将其也包括在您的问题中。@TokenMacGuy:您是对的。据我所知,我将使用“SQLite 3数据库库”。这有帮助吗?还是你有更具体的想法?谢谢!我甚至不知道SQLITE\u MASTER存在。但接下来的问题是:
rootpage
是我一直在寻找的索引,还是我不应该随意改变它?是数据库中对象的第一个B树页面。不要改变它:)
cursor.execute(
    "SELECT tbl_name FROM sqlite_master WHERE type='table'")

table_names = cursor.fetchall()
PRAGMA table_info(table-name);