# Async command

#### Syntax

    ASYNC Identifier String

#### Description

The ASYNC command lets you execute an SQL statement in a separate thread. It is used in conjunction with the Wait For command to get the results.

You supply the SQL statement, which is any valid SQL statement, as a String. The Identifier you must supply for the async SQL statement is used in the Wait For command and is a case-insensitive `ij` identifier. An identifier that does not specify a connectionName must not be the same as any other identifier for an async statement on the current connection; an identifier that specifies a connectionName must not be the same as any other identifier for an async statement on the designated connection. You cannot reference a statement previously prepared and named by the `ij` Prepare command in this command.

`ij` creates a new thread in the current or designated connection to issue the SQL statement. The separate thread is closed once the statement completes.

#### Examples

    ij> async aInsert 'INSERT into menu values (''entree'',''chicken'',11)';
    ij> INSERT INTO menu VALUES ('dessert','ice cream',3);
    1 rows inserted/updated/deleted.
    ij> wait for aInsert;
    1 rows inserted/updated/deleted.
    -- the result of the asynchronous insert

    ij> connect 'jdbc:derby:memory:dummy;create=true;user=john'
        as john_conn;
    ij> create table john_tbl (c int);
    0 rows inserted/updated/deleted
    ij> insert into john_tbl values(1),(2),(3);
    3 rows inserted/updated/deleted
    ij> connect 'jdbc:derby:memory:dummy;user=fred' as fred_conn;
    ij(FRED_CONN)> async john_async @ john_conn 'select * from john_tbl';
    ij(FRED_CONN)> wait for john_async @ john_conn;
    C
    -----------
    1
    2
    3

    3 rows selected
    ij(FRED_CONN)>

Parent topic: ij commands and errors reference
Related concepts
ij commands
ij errors
Related reference
Absolute command
After Last command
Autocommit command
Before First command
Close command
Commit command
Connect command
Describe command
Disconnect command
Driver command
Elapsedtime command
Execute command
Exit command
First command
Get Cursor command
Get Scroll Insensitive Cursor command
Help command
Last command
LocalizedDisplay command
MaximumDisplayWidth command
Next command
Prepare command
Previous command
Protocol command
Readonly command
Relative command
Remove command
Rollback command
Run command
Set Connection command
Show command
Wait For command
Syntax for comments in ij commands
Syntax for identifiers in ij commands
Syntax for strings in ij commands