给定一个SQLite数据库。SQLite:如何使用正确名称提取主键和唯一约束
与主键的表:
create table t1 (id int not null, CONSTRAINT pk_id PRIMARY KEY (id));
现在查询信息吧:
PRAGMA TABLE_INFO(t1);
回报:
| cid | name | type | notnull | dflt_value | pk | | --- | ---- | ---- | ------- | -----------| -- | | 0 | id | int | 1 | <null> | 1 |
PRAGMA index_list(t1);
回报:
| seq | name | unique | origin | partial | | --- | ----------------------| ------ | ------ | ------- | | 0 | sqlite_autoindex_t1_1 | 1 | pk | 0 |
我们可以看到关于PK index_list
回报的信息,但其报告不正确的名称(“sqlite_autoindex_t1_1”而不是“pk_t1”)。
与UNIQUE约束相同的问题。它们是使用自动生成的名称创建的。
是否可以提取真正的PRIMARY KEY/UNIQUE CONSTRAINT名称?
P.S.我可以看到JetBrains的DataGrip在数据库浏览器中正确显示PK名称。但sqliteadmin例如显示它们的名字,如sqlite_autoindex_t1_1。对于唯一的约束,即使DataGrip不显示正确的名称(实际上它根本不显示它们)。