Re: Create table and index in one script

Fred Toussi <[email protected]> Mon, 16 Jan 2017 11:02:38 +0000
Newsgroups gmane.comp.java.hsqldb.user
Message-ID <1484564558.4084911.849017048.4F8E04E5@webmail.messagingengine.com>
The statements are compiled before they are executed. The CREATE INDEX
statements is compiled before the table is created therefore compilation
fails due to the non-existent table.
 

It is possible to create a whole schema in one transaction, including
all the constraints and indexes. See the Guide, Schemas and Database
Objects chapter. In the example below, note the lack of semicolon at the
end of inner statements and the single semicolon at the end:
 

 CREATE SCHEMA ACCOUNTS AUTHORIZATION DBA   CREATE TABLE AB(A INTEGER)
 CREATE TABLE CD(C CHAR(10))   CREATE INDEX IDX ON AB(A);
 

Fred Toussi

 

On Thu, Jan 12, 2017, at 23:35, Keith Squier wrote:

> I am having difficulty creating tables and indexes all in one script.
> A simple example is below.
>  

> CREATE TABLE A (

>    id UUID NOT NULL,

>    datetime TIMESTAMP NOT NULL,

>    PRIMARY KEY (id));

>  

> CREATE INDEX a_datetime_idx ON A (datetime);

>  

> When I run both statements in a single transaction, I get errors that
> the table is not found. If I run them in separate transactions,
> everything works. Is it not possible to create tables and their
> indexes all in one transaction?
> ----------------------------------------------------------------------
> --------
> Developer Access Program for Intel Xeon Phi Processors

> Access to Intel Xeon Phi processor-based developer platforms.

> With one year of Intel Parallel Studio XE.

> Training and support from Colfax.

> Order your platform today. http://sdm.link/xeonphi

> _________________________________________________

> Hsqldb-user mailing list

> [email protected]

> https://lists.sourceforge.net/lists/listinfo/hsqldb-user

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi

_______________________________________________
Hsqldb-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user