Is it possible to include sql files within another sql file in H2 database.
I have 5 sql files
1) create-tables.sql
2) insert-data.sql
1) data-1.sql
2) data-2.sql
3) data-3.sql
In this example i want to include data-1.sql, data-2.sql, data-3.sql within insert-data.sql
testProperty.connection.driverClass=org.h2.Driver testProperty.connection.url=jdbc:h2:file:./target/db/testdb;AUTO_SERVER=TRUE;LOCK_TIMEOUT=10000;INIT=runscript from 'src/test/resources/sql/create-tables.sql'\;runscript from 'src/test/resources/sql/insert-data.sql' testProperty.connection.username=sa testProperty.connection.password=
I have tried the following commands in insert-data.sql, but not working
\source data-1.sql
@data-1.sql
\include data-1.sql
CodePudding user response:
There are no directives is SQL scripts for H2. But you can run the same RUNSCRIPT
command from a script launched with this command:
src/test/resources/sql/insert-data.sql
:
RUNSCRIPT FROM 'src/test/resources/sql/data-1.sql';
-- commands
src/test/resources/sql/data-1.sql
:
-- commands
Please note that relative paths will be treated as relative to the current working directory of the process and not as relative to the script with this command.