Defining a database
To define a database, you must have a project defined. Once your project is defined, follow these steps:
To access the Data Definition view:
Click Window > Open Perspective > Other to open the Select Perspective dialog.
Select Data and click OK.
Select the Data Definition tab to switch to the Data Definition view if it is not already showing.
From the pop-up menu of a project where you want to create the database, click New > New database definition. The New Database Definition wizard opens.
In the Database name field, type the name of the database that you want to create.
Select the database vendor type. When you generate SQL DDL for your schemas, it conforms to the database type that you select here.
Click Finish. The wizard closes, and your database appears under the project folder.
Defining a schema
After you have created a database, you can define schemas to organize the tables and other data objects.
To define a schema, follow these steps after you have defined a database:
Switch to the Data perspective's Data Definition view.
From the pop-up menu of your database, click New > New schema definition. The New Schema Definition dialog opens.
In the Schema name field, type the name of the schema that you want to create, and click Finish. The schema is added to the database folder.
Expand the schema to display the folders underneath it. You can use these folders to add the rest of your data objects such as tables.
Defining a table
Tables are logical structures maintained by the database manager. Tables are made up of columns and rows. You can define tables as part of your data definitions in the Data perspective. Before you can define a table, you must first have a database and a schema defined.
To define a table in your database, follow these steps:
In the Data Definition view of the Data perspective, select the Tables folder under your schema.
From the pop-up menu of the folder, click New > New table definition to open the New Table Definition wizard.
Follow the prompts in the wizard to define table properties, add columns, and define primary and foreign keys.
Click Finish. The table is added to the Tables folder.
You must define at least one column and a primary key for the table. You can define foreign keys if you have other tables already defined.
NOTE: If you delete a primary key (either by removing the constraint, its columns, or the table that defines it), any foreign key constraints that reference the key are also removed.
You can edit the table information, add or delete columns, change the primary key, and add or delete foreign keys afterwards by using the table editor. To open the table editor, double-clicking on the table in the Data Definition view.
Deploying to the database
You can define, generate, and apply SQL Data Definition Language (DDL) statements in the Data Definition view of the Data perspective.
Data Definition Language (DDL) is a subset of SQL. It is a language for describing data and its relationships in a database. Use the Generate SQL DDL diaog to generate SQL DDL statements used to recreate a database object.
You might want to generate SQL DDL statements for database objects for the following reasons:
To keep a snapshot of what the database looks like.
To set up a test system where the database acts like the production system but contains no data.
Generating an SQL DDL file
You can generate an SQL DLL file for an object. SQL DDL statements are used to change the structure of the database, such as define a new table, change the definition of a table, and remove a table.
Once you have created data definitions in your Data perspective, you can generate the SQL DDL file for the data object as follows:
If the file that you want to re-generate is currently open in an editor, you will be prompted to reload the changes. At this time, you need to decide whether or not you want to keep the changes.
From the pop-up menu of the database node, table, schema, or the view objects, click Generate DDL to open the Generate SQL DDL dialog:
Provide the name and target location for the generated file. By default, it is named after the currently selected data object, and placed in the same project.
Select whether to use fully qualified names (including the target schemas for the statements).
Select whether to generate delimited identifiers. Place quotation marks around the identifiers.
Select whether to generate the associated DROP statement for each CREATE statement contained in the resulting script.
Select the Open SQL DDL file for editing when done check box to immediately start editing the file once it is generated:
Click Finish to generate the file.
The SQL DDL script is now visible under the target project:
Applying DDL scripts to a remote database
You can apply the statements defined in an SQL DDL file by running the script against a remote database.
Switch to the Data perspective's Data Definition view.
Locate the SQL DDL script that you want to apply. The SQL DDL script has the file name extension .sql. If the script is not showing up in the Data Definition view, check your Data Definition filter preference (Menu button in Data Definition view and then click Filters) to make sure it is not being filtered out.
From the script's pop-up menu, click Run on Database Server to open the Run Script wizard.
Select the statements that you want to execute against the remote database.
Click Next to open the Run Script Options wizard.
Select the options to be used when running the script.
Click Next to switches to the Database Connection page of the wizard.
Complete the required fields needed to establish a JDBC connection to the remote database you wish to apply the DDL to.