H2 ddl create table

Viewed 1125

I would like to know if it is possible to get the H2 ddl create table from the

http://localhost:5678/pecador/console/

I have tried show columns from T_USER ;

but it only shows the columns

1 Answers

If you want to get SQL for a table T_USER, you can use one of two following commands in H2:

SCRIPT NODATA NOPASSWORDS NOSETTINGS TABLE T_NAME;
SELECT SQL FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'T_NAME';

The first one also returns some unrelated elements. Actually you can dump the whole database with it, check its documentation for details: https://h2database.com/html/commands.html#script

The second one returns only the SQL of the specified table (unless you have tables with the same name in multiple schemas, but you can add AND SCHEMA_NAME = 'PUBLIC' to exclude them). Note that you need to specify 'T_NAME' in its real case, if you're using ;DATABASE_TO_LOWER=TRUE setting it is 't_name'. Beware: presence of INFORMATION_SCHEMA.TABLES.SQL column in future versions of H2 is not guaranteed.

Related