Inspect Hsqldb Schema

雨燕双飞 提交于 2019-12-23 15:00:36

问题


Is it possible to inspect and subsequently modify an existing schema in Hsqldb standalone mode? I've tried looking at the file using the built in admin tool as well as hooking up SQuirrel SQL Client.

I'm particularly interested in what primary keys exist on various tables. Is there command equivalent to MySql's 'show create table...' or 'describe '?


回答1:


The sqltool \d command approximates a "describe", and primary key information is stored under the INFORMATION_SCHEMA:

sql> CREATE SCHEMA STACKOVERFLOW;
sql> SET SCHEMA STACKOVERFLOW;
sql> CREATE TABLE SO2406470 (pk1 INT NOT NULL, pk2 INT NOT NULL, data VARCHAR(64), PRIMARY KEY(pk1, pk2));
sql> \d SO2406470
name  datatype  width  no-nulls
----  --------  -----  --------
PK1   INTEGER      11  *
PK2   INTEGER      11  *
DATA  VARCHAR      64  
sql> SELECT * FROM INFORMATION_SCHEMA.SYSTEM_PRIMARYKEYS WHERE TABLE_SCHEM = CURRENT_SCHEMA AND TABLE_NAME = 'SO2406470';
TABLE_CAT  TABLE_SCHEM    TABLE_NAME  COLUMN_NAME  KEY_SEQ  PK_NAME
---------  -------------  ----------  -----------  -------  ------------
PUBLIC     STACKOVERFLOW  SO2406470   PK1                1  SYS_PK_10040
PUBLIC     STACKOVERFLOW  SO2406470   PK2                2  SYS_PK_10040

Fetched 2 rows

(hsqldb-2.0.0rc9)




回答2:


The sqltool \dt command will show all table names, and \d? command will show all 'describe' options.

sql> \dt
TABLE_SCHEM  TABLE_NAME
-----------  ---------------
PUBLIC       APP_CFG
PUBLIC       CFG_REFRESH_LOG
...
sql> \d?
\dX [parameter...] where X is one of the following.
    a:  list Aliases
    c:  list Catalogs
    i:  list Indexes (for some databases, must specify literal target table)
    n:  list schema Names
    r:  list Roles
    s:  list Sequences
    S:  list System tables
    t:  list Tables
    u:  list Users
    v:  list Views
    *:  list table-like objects
    ...


来源:https://stackoverflow.com/questions/2406470/inspect-hsqldb-schema

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!