dblook examples

The following examples demonstrate how the various dblook utility options can be specified from a command line. These examples use the sample database.

Note: The quotation marks shown in these examples are part of the command argument and must be passed to dblook. The way in which quotation marks are passed depends on the operating system and command line that you are using. With some systems it might be necessary to escape the quotation marks by using a forward slash before the quotation mark. For example:
"\"My Table"\"

Status messages are written to the output (either a -o filename, if specified, or the console) as SQL script comments. These status messages serve as headers to show which types of database objects are being, or have been, processed by the dblook utility.

Writing the DDL to the console

You can write the DDL to the console for everything that is in the sample database. In this example, the database is in the current directory. For example:

java org.apache.derby.tools.dblook -d jdbc:derby:sample

Including error and warning messages in the dblook command

You can write error and warning messages when you write the DDL to the console. The messages are written using System.err. For example:

java org.apache.derby.tools.dblook -d jdbc:derby:sample -verbose

Writing the DDL to a file

You can write the DDL to a file called myDB_DDL.sql for everything that is in the sample database. In this example, the database and file are in the current directory. For example:

java org.apache.derby.tools.dblook -d jdbc:derby:sample -o myDB_DDL.sql

Specifying directory paths in the dblook command

If the database or file is not in the current directory, you must specify the directory path. For example:

java org.apache.derby.tools.dblook -d 'jdbc:derby:c:\private\stuff\sample'
   -o 'C:\temp\newDB.sql'

Specifying a schema in the dblook command

You can specify the schema for the database. To write the DDL to the console, for all of the objects in the sample database where the database is in the SAMP schema, use the following command:

java org.apache.derby.tools.dblook -d jdbc:derby:sample -z samp

Specifying a remote database and host

If the sample database is in the SAMP schema on localhost:1527, you must specify your user ID and password. For example, use the following command to write the DDL to the console:

java org.apache.derby.tools.dblook
   -d 'jdbc:derby://localhost:1527/"C:\temp\sample";
   user=someusername;password=somepassword' -z samp

Specifying a schema and a table within the database in the dblook command

You can specify that only the objects in the sample database that are associated with the SAMP and the My Table table are written to the console. For example:

java org.apache.derby.tools.dblook -d jdbc:derby:sample -z samp -t "My Table"

Specifying multiple tables in the dblook command

You can specify more than one table in the dblook command by separating the names of the tables with a space. For example, for objects in the sample database that are associated with either the My Table table or the STAFF table, use the following command:

java org.apache.derby.tools.dblook -d jdbc:derby:sample -t "My Table" staff

Writing DDL to a file without a statement delimiter

To write the DDL for all of the objects in the sample database to the myDB_DDL.sql file without a statement delimiter, you must omit the default semicolon. You can append the DDL to the output files if the files are already there. For example:

java org.apache.derby.tools.dblook -d jdbc:derby:sample
   -o myDB_DDL.sql -td '' -append

Excluding views from the DDL

To write the DDL to the console for all of the objects in the sample database except for views, use the following command:

java org.apache.derby.tools.dblook -d jdbc:derby:sample -noview
Related concepts
Using dblook
Generating the DDL for a database
Related reference
dblook options