SQL programming / SQL basics |
Understanding the implicit database connection with DATABASE instruction used before MAIN.
The DATABASE statement can be used in two distinct ways, depending on the context of the statement within its source module:
DATABASE stock_dev -- Default database, used at compile time DEFINE p_cust RECORD LIKE customer.* MAIN -- Connection to default database occurs at MAIN DEFINE dbname CHAR(30) LET dbname = "stock1" DATABASE dbname -- Real database used in production ... END MAIN
SCHEMA stock_dev -- Schema specification only DEFINE p_cust RECORD LIKE customer.* MAIN -- No default connection occurs... DEFINE dbname CHAR(30) LET dbname = "stock1" DATABASE dbname END MAIN
This instruction will define the database schema for compilation only, and will not make an implicit connection at runtime.