Question

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 '?

Was it helpful?

Solution

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)

OTHER TIPS

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
    ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top