getDatabaseDDL
First introduced in version 3.00.6
Syntax
getDatabaseDDL(dbHandle)
Details
Gets the database creation statement for the target database.
-
The target database must be a DFS database.
-
A user can get the database creation statement only if at least one of the following conditions is met:
-
The user is a DolphinDB administrator (admin).
-
The user has the management permission (DB_MANAGE) on the target database.
-
The user is the owner (DB_OWNER) of the target database.
-
The user has read (DB_READ), write (DB_WRITE), insert (DB_INSERT), update (DB_UPDATE), or delete (DB_DELETE) permission on the target database.
-
The user has object creation (DBOBJ_CREATE) or deletion (DBOBJ_DELETE) permission on the target database.
-
Parameters
dbHandle is a STRING scalar or database object that specifies the target database.
Returns
A STRING scalar that indicates the database creation statement.
Examples
Example 1: Create the dfs://compoDB database and get its database creation statement. You can execute the statement directly by using runScript. In the following example, the database schemas created in the two operations (schema1 and schema2) are identical.
dbDate=database(, VALUE, 2026.08.07..2026.08.11)
dbID=database(, RANGE, 0 50 100)
db=database("dfs://compoDB", COMPO, [dbDate, dbID])
schema1=db.schema()
DDL=getDatabaseDDL(db)
DDL
/Output: 'create database "dfs://compoDB" partitioned by VALUE(2026.08.07..2026.08.11), RANGE([0,50,100]), engine=OLAP, atomic=TRANS, chunkGranularity=TABLE'/
dropDatabase("dfs://compoDB")
runScript(DDL)
schema2=database("dfs://compoDB").schema()
runScript. In the following example, the database schemas
created in the two operations (schema1 and schema2) are
identical.if(!existsCatalog("test")){
createCatalog("test")
}
if(size(exec schema from getSchemaByCatalog("test") where schema = "compoDB") > 0){
dropSchema("test", "compoDB")
}
go
use catalog test
create database compoDB partitioned by VALUE(2026.08.07..2026.08.11), RANGE(0 50 100)
dbUrl = exec dbUrl from getSchemaByCatalog("test") where schema = "compoDB"
db=database(dbUrl[0])
schema1=schema(db)
DDL=getDatabaseDDL(db)
DDL // The DFS path in the output is randomly generated and is for reference only.
/Output: 'create database "dfs://test_compoDB_1781022930257" partitioned by VALUE(2026.08.07..2026.08.11), RANGE([0,50,100]), engine=OLAP, atomic=TRANS, chunkGranularity=TABLE'/
dropDatabase(dbUrl[0])
runScript(DDL)
createSchema("test", dbUrl[0], "compoDB") // Add the DFS database to the test data catalog.
dbUrl = exec dbUrl from getSchemaByCatalog("test") where schema = "compoDB"
db=database(dbUrl[0])
schema2=schema(db)Related functions: database, runScript, getDBTableDDL
