JDeveloper provides a set of modeling tools which allow you to visually create tables on a diagram. You can create new tables directly on a database diagram, or import existing tables from a database schema, or work with offline tables in the navigator and then drag them on a diagram to work with them further. Once you have finished modeling the tables, you can generate the changes directly to the database, or create a DDL file to be run later.
You can create and edit database components directly on a database diagram. This is called in-place editing. For instance, you can create or edit columns, or edit keys and constraints on a modeled table, or draw foreign key relationships between tables directly on the diagram. You can import tables from a live database connection by dragging them directly onto a diagram and reconcile your changes with the database and create the DDL to generate the changes back to the database.
This tutorial discusses the following:
1 hour
Move your mouse over this icon to show
all screenshots. You can also move your mouse over each individual icon to see
only the screenshot associated with it.
The tutorial guides you through the process of importing two tables from the Human Resources schema on the database. This will give you two offline table definitions which you can edit and manipulate on a diagram. You will also create an offline table directly onto the diagram.
Once you have finished working with the offline tables, you will create the DDL to create the new tables in the new schema.
In order for this tutorial to work successfully, you will need to have performed the following:
| 1. | Install Oracle JDeveloper 10g.
|
| 2. | Install the Sample Schemas and create a connection to the HR or HR8 schema. See Installing the Sample Schemas and Establishing a Database Connection tutorial. |
When you work in JDeveloper, you organize your work in projects within application workspaces. JDeveloper provides a number of predefined templates which allow you to create a workspace and projects that are configured for developing the types of application you are working on. The templates provide the basic range of technologies that are needed, and you create your working environment by selecting the one that fits your needs, then configuring it to add any additional technologies you are going to use. The options that are available to you in the New Gallery and for some context menu operations depend on your choice of template for that workspace.
In this tutorial you are going to choose the default web application template, and customize it to make JDeveloper's database functionality available.
| 1. | In the Applications Navigator, right-click
Applications and choose New from the context menu.
|
| 2. | In the Create Application Workspace dialog, rename the application Application1 to DBModeling. Notice that the directory name changes to match the new name.
|
| 3 . | Before selecting the application template, you are going to customize it. Click Manage Templates to open the Manage Application Templates dialog.
|
| 4 . | Under the Web
Application [Default] node, select Data
Model. Locate Database
in the available technologies list and move it to the selected technologies
list, then click OK.
|
| 5 . | The DBModeling
workspace is created and displayed as a node in the navigator.
|
In this step you will create a database diagram.
| 1. | With the Model project selected
in the Application Navigator, right-click and choose New
from the context menu. This opens the New Gallery.
|
| 2. | In the Categories list, select Offline
Database Objects in the Categories list, then select Database
Diagram from the Items list. Click OK to open
the Create Database Diagram dialog.
|
| 3 . | Accept the defaults and click OK. A new
database diagram opens. You should see the Component Palette, which shows
the elements available for you to use on this diagram. If you can't see
it, open it by choosing Component Palette from the
View menu.
|
Now that you have a blank database diagram, you can directly import tables from the database connection by dragging them onto the diagram. Importing the tables creates the offline table definitions which you will work with before creating the DDL to create new tables in a database.
| 1. | To import tables from the connection you have
to the database, click the Connections tab so that the
Connections Navigator is visible, or choose View | Connection
Navigator. Expand the Database,
and HR nodes to
see all the database elements available through this connection.
|
| 2. | Filter the list to make it easier to work with. Select the HR node, then click Filter. In the Filter Object Types dialog, move all the object types except Tables from the list of displayed object types to the list of available object types. Click OK.
|
| 3 . | Expand the Tables node and select DEPARTMENTS,
hold down the Ctrl key and select EMPLOYEES.
|
| 4 . | Drag DEPARTMENTS and EMPLOYEES onto the diagram. In the
Create from Tables dialog, ensure that Offline Tables is selected and
click OK. JDeveloper connects to the database and creates
offline table definitions based on the tables you have selected. There
may be a short delay while this occurs.
|
| 5 . | The offline tables and foreign keys are created and displayed
on the diagram. You can see a thumbnail view of the diagram by clicking
the Thumbnail tab in the Structure pane. The default position of this
pane is at the lower left corner of JDeveloper. If you can't find it,
choose View | Thumbnail.
|
| 6 . | The offline tables also appear in the Application Navigator, in the Model project under the Database Objects node. Notice that they are grouped in an offline schema called model. The offline schema is a container for offline database objects.
|
JDeveloper's modeling tools allow you to edit offline tables directly on the diagram, called in-place editing. You can change the name of a table, create new columns, edit existing columns, and edit constraints on the table.
| 1. | In the second compartment of the diagrammed
table, click in the LAST_NAME
column to select it, then click again so you can edit the line, and change
the field size to 30.
|
| 2. | In the third compartment, select the check constraint that says <<Check>> EMP_SALARY_MIN:salary > 0 and change it to EMP_SALARY_MIN:salary > 10.
|
| 3 . | Now try comparing in line editing with editing using the Edit Offline Tables dialog. Open the Edit Offline Tables dialog by doing one of the following: Use the in line editing from the diagram
|
In addition to importing existing tables from a database, you can create new tables directly on the diagram.
| 1. | In the component palette, click on Table,
then click on the diagram. A new offline table is created on the diagram,
and it appears in the Application Navigator in the model
schema. Resize it so that it is easier to work with.
|
| 2. | Change the default name of the table to REGIONS.
In the second compartment of the modeled table, create two columns by
typing REGION_ID : CHAR(2)
on one line, then REGION_NAME
: VARCHAR2(40) on the next.
|
| 3 . | In the third compartment, you can see that a primary key
has been automatically created from the first column you created. We'll
use this to link it to the Departments table.
|
| 4 . | Make sure you can see both the Departments
and Regions tables in the
modeler. Use the Thumbnail pane and move the shape that shows the visible
area to include both tables, or you can use click the Zoom Out button
at the bottom right of the diagram pane.
|
| 5 . | The foreign key relationship is displayed on the diagram,
and the table with the foreign key, Departments,
now has an extra column named
REGIONS_REGION_ID : CHAR(2).
|
In the previous steps, you have seen how to import tables from a database connection, as well as how to create new tables on a database diagram. In this step you will create a SQL file containing the DDL which you could use to create the tables in a database.
JDeveloper also allows you to generate directly to a database, or to reconcile your changes against a database.
| 1. | To generate a SQL script:
|
| 2. | If the first page of the wizard is displayed, review the
information and click Next.
|
| 3 . | On the Generate Options page, ensure that just the following
are selected: These will ensure that a script is created, and that it contains CREATE statements, rather than UPDATE statements.
|
| 4 . | On the SQL Script Options page, change the SQL file name
from untitled.sql to
dbmodeling.sql. The SQL script is listed in the Application Navigator in the Model project under the Resources node. Double-click on dbmodeling.sql to open it in JDeveloper's SQL editor and view the CREATE and ALTER statements.
|
This part of the tutorial shows you how you can customize database diagrams to suit your way of working. Try one or more of the following tasks.
| 1. | To change the way the diagram is viewed: Zoom in and out using the buttons at the bottom right corner of the diagram.
|
| 2. | To resize and move diagram elements: Move one of the tables and the foreign keys move as well. If you end
up with unnecessary points on the foreign keys, right click on a line
and choose Straighten Lines from the context menu. Alternatively
you can let JDeveloper automatically lay out the tables by choosing Lay
Out Shapes from the context menu, followed by one of the available
options.
|
| 3 . | To change the colors of the diagram elements: Change the default colors that are used in the creation of new diagram
elements, by choosing Preferences form the Tools
menu. Select the Diagrams
node, then Diagram, then
Database.
Continue selecting the nodes under database to change the color, font
and shape of foreign keys and tables.
|
In this tutorial, you've learned how to:
![]() |
Create a new application workspace | |
![]() |
Create an empty database diagram. | |
![]() |
Start modeling database objects by importing tables from a live database connection. | |
![]() |
Edit tables on the diagram using in-place editing. |
|
![]() |
Create a new offline table on the diagram from the component palette. | |
![]() |
Create a foreign key relationship between two tables. | |
![]() |
Use the JDeveloper functionality to change the look of your diagram. | |
![]() |
Generate a SQL file from your work which you could run against a database connection to create the tables in the database. | |
Move your mouse over this icon
to hide all screenshots