|
The database can be generated from either Entity Relationship Diagram or Class Diagram. You are allowed to configure the database connection and generate the database schema by exporting the Entity Relationship Diagram or Class Diagram to relational database. This chapter shows you how to generate the database and data definition language and describes how the data model maps the data definition language.
In this chapter:
Database schema refers to the database structure while data definition language (DDL) is a database language which describes the data structure in a database; that is, the DDL is used to define the database schema. The DDL statements support the creation and destruction of a database and/or table.
As the visual modeling of data model is supported, database connection is allowed to configure to the working environment. According to the data model, the database and DDL can also be generated.
SDE provides you with two ways to generate a relational database:
You can generate the database from data model in one of the two ways:
![]() |
|---|
| Figure 16.1 - To generate database |
For other SDE:
| SDE | Method |
|---|---|
| SDE for JBuilder | On the menu, click Tools > Modeling > ORM > Generate Database.... |
| SDE for NetBeans | On the menu, click Modeling > ORM > Generate Database.... |
| SDE for IntelliJ IDEA | On the menu, click Modeling > ORM > Generate Database.... |
| SDE for JDeveloper | On the menu, click Model > ORM > Generate Database.... |
| SDE for WebLogic Workshop | On the menu, click Modeling > ORM > Generate Database.... |
The Database Code Generation dialog box is displayed.
For generating database for a Java project, configure the following options.
You are allowed to define the database configuration. Refer to the descriptions in the Database Configuration for Java Project in the Getting Started with Object-Relational Mapping chapter for information on how to configure the database for Java project.
![]() |
|---|
| Figure 16.2 - Database Code Generation dialog |
| Figure 16.3 - Export to database checkbox |
| Figure 16.4 - Generate DLL checkbox |
![]() |
|---|
| Figure 16.5 - Quote SQL Identifier options |
![]() |
|---|
| Figure 16.6 - Connection Type |
| Figure 16.7 - Use connection pool |
![]() |
|---|
| Figure 16.8 - Connection Pool Options dialog |
![]() |
|---|
| Figure 16.9 - Generate ORM Code/Database dialog |
The database tables are generated.
| You are allowed to generate the database by selecting Create Database, Update Database, Drop and Create Database or Drop Database from the drop down menu. |
![]() |
|---|
| Figure 16.10 - Generate database options |
For generating database for a .NET project, configure the following options.
You are allowed to define the database configuration. Refer to the descriptions in the Database Configuration for .NET Project in the Getting Started with Object-Relational Mapping chapter for information on how to configure the database for .NET project.
![]() |
|---|
| Figure 16.11 - Database Code Generation dialog |
| Figure 16.12 - Export to database checkbox |
| Figure 16.13 - Generate DDL checkbox |
![]() |
|---|
| Figure 16.14 - Quote SQL Identifier options |
![]() |
|---|
| Figure 16.15 - Generate ORM Code/Database |
he database tables are generated.
| You are allowed to generate the database by selecting Create Database, Update Database, Drop and Create Database or Drop Database from the drop-down menu. |
![]() |
|---|
| Figure 16.16 - Generate database options |
For information on generating database from data model by using wizard, refer to the descriptions in the Using ORM Wizard chapter.
You can generate the database from object model by using wizard. For information, refers to the descriptions in the Using ORM Wizard chapter.
As the database can be generated, it supports mapping from Data Model to Data Definition Language (DDL)
The following table shows the mapping between Data Model and DDL.
| Data Model | DDL |
|---|---|
| Entity | Table |
| Column | Column |
| Data Type | Data Type |
| Primary Key | Primary Key |
| Foreign Key | Foreign Key |
Example:
![]() |
|---|
| Figure 16.17 - Entity Relationship Diagram |
The following DDL statements are generated by the above data model:
create table 'Department' ('ID' int not null auto_increment, 'DeptName' varchar(255), primary key ('ID'))
create table 'Staff' ('ID' int not null auto_increment, 'Name' varchar(255), 'Address' varchar(255), 'Phone' varchar(255), 'Email' varchar(255), 'OfficeExtension' varchar(255), 'DepartmentID' int not null, primary key ('ID'))
alter table 'Staff' add index 'FK_Staff_4271' ('DepartmentID'), add constraint 'FK_Staff_4271' foreign key ('DepartmentID') references 'Department' ('ID')
The following figure illustrates the mapping between Data Model and DDL.
![]() |
|---|
| Figure 16.18 - Mapping between Data Model and DDL |
The Staff entity maps to Staff table of the DDL; the primary key of Department entity maps to DDL for creating "primary key (ID)" constraint; the column Name of Staff entity maps to a column Name of the staff table to be generated; the data type of DeptName, which is varchar maps to "varchar(255)" to the DDL; the column DepartmentID of Staff Entity maps to the DDL for creating a foreign key constraint.
|
|
|||||||