Creating a Database Using Dynamic SQL
From InterBase
Go Up to DSQL Limitations (Using Dynamic SQL)
To create a new database in a DSQL application:
- Disconnect from any currently attached databases. Disconnecting from a database automatically sets its database handle to
NULL
. - Build the
CREATE DATABASE
statement to process. - Execute the statement with
EXECUTE IMMEDIATE
.
For example, the following statements disconnect from any currently connected databases, and create a new database. Any existing database handles are set to NULL
, so that they can be used to connect to the new database in future DSQL statements.
char *str = "CREATE DATABASE \"new_emp.ib\""; . . . EXEC SQL DISCONNECT ALL; EXEC SQL EXECUTE IMMEDIATE :str;