designing and building database tables--oracle jdeveloper 11g release 2

Upload: swati

Post on 07-Oct-2015

3 views

Category:

Documents


0 download

DESCRIPTION

ADF 11g

TRANSCRIPT

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 1/40

    Designing and Building Database Tables

    In this tutorial, you will create an application and a project in which to organize your database files. You connect to a database and create a newuser, then work in Oracle JDeveloper to create an offline database that you will reverse-engineer.

    Purpose Duration Application

    This tutorial shows you how to create a database diagram with database components. You'llsee how to create a database user, reconcile the offline definitions with the current databasedefinitions, and generate a DDL reconciliation script. Finally you reverse-engineer databaseobjects. To see the complete application you will create, click the Download button to download a zipof the final application. Unzip it into your JDeveloper folder.

    40 minutes

    Step 1: Create a New Application and Project

    The JDeveloper application is the highest level in the organizational structure. It stores information about the objects you are working with, whileyou are creating your application. It keeps track of your projects and the environment settings while you are developing.

    1. Start JDeveloper by selecting Start > All Programs > Oracle Fusion Middleware 11.1.2 > JDeveloper Studio 11.1.2

    2. If prompted for a Role, choose Database Developer and click OK.

    3. Close the Tip of the Day window.

    4. In the Applications Navigator, click New Application.

    5. In the New Gallery, select General | Applications and choose Database Application.

    Once loaded, the JDeveloper IDE appears.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 2/40

    Click OK.

    6. In the Create Database Application dialog, change the Application Name from Application1 to CreateDBObjects and type oracle as theApplication Package Prefix. Notice that the Directory Name automatically changes to match the new Application Name.

    Click Next.

    7. In Step 2 of the Wizard enter NewSchema as the Project Name.

    Click Finish.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 3/40

    8. The Application Navigator should look like the following:

    9. Save your work by clicking Save All . You should save your work at regular intervals as you progress through the rest of the tutorial.

    Step 2: Create a Database Diagram

    One way to develop offline database object definitions is by using a database diagram. You can create offline tables, foreign key relationships,views, synonyms, sequences, usages, and joins directly on the diagram. You drag components from the Component Palette onto the diagram,then draw relationships and annotations, such as attachments and dependencies, between objects. A form of UML notation is used to representeach of the objects on the diagram. Each component you create on the diagram is also displayed in the Application Navigator. To begin creatinga database diagram, you will open the Create Database Diagram dialog.

    1. To open the dialog, choose File | New.

    2. In the New Gallery, expand Database Tier and select Offline Database Objects, then select Database Diagram.

    Click OK.

    3. In the Create Database Diagram dialog, enter Database Diagram as the name.

    When you work in JDeveloper, you organize your work in projects within applications.

    In the Application Navigator, Projects panel, projects are displayed as the top level in the hierarchy.

    From the diagram, you can edit your objects with in-place editing.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 4/40

    Click OK.

    4. A new empty diagram opens.

    5. Make sure the Component Palette displays the Database components.

    6. From the Component Palette, drag and drop the table icon component onto the diagram.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 5/40

    7. In the Specify Location dialog, select Application Project. Click New to open the Create Offline Database dialog.

    8. Enter DBOffline1 as the database name, and DBDEMO as the default schema name.

    Click OK. Click OK again to close the Specify Location dialog.

    9. The Application Navigator displays the new offline database diagram and table.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 6/40

    10. The database diagram displays the default table, named TABLE1.

    11. Click Save All to save your work.

    Step 3: Create Offline Database Tables on a Diagram

    You can use JDeveloper to work directly with database objects through a database connection. Alternatively, you can work with offline databasedefinitions which you can subsequently generate to a database schema.

    1. In the database diagram, select the new table name TABLE1, and change it by typing PERSONS. Then press Enter or Tab.

    2. To add a column definition, click in the white box under the table name, then click again to expose the default format. TypePERSON_ID:NUMBER(15,0) and press Tab.

    3. With the default format exposed in the next box, add the column definitions FIRST_NAME:VARCHAR2(30 BYTE),LAST_NAME:VARCHAR2(30 BYTE) and GENDER:VARCHAR2(1 BYTE), one at a time pressing Tab to advance to the next.

    You can create new tables and views and generate the information to a database.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 7/40

    4. Double-click the PERSONS table component on the diagram to open the Edit Table dialog, where you can create a primary key.

    5. Select Primary Key in the navigation panel, then shuttle PERSON_ID from the Available Columns list to the Selected Columns list.

    Click OK. A unique index is automatically added for the primary key.

    6. In the Component Palette, drag and drop a Table component onto the diagram. Then change the table name to ADDRESSES.

    When you see the default format exposed in the box, you can type over the default text.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 8/40

    7. In the ADDRESSES table, add the following column definitions: ADDRESS_ID:NUMBER(10,0), ADDRESS_LINE1:VARCHAR2(40) andADDRESS_LINE2:VARCHAR2(240).

    8. Double-click the ADDRESSES table component on the diagram to open the Edit Table dialog, where you can create a primary key.

    9. Select Primary Key in the navigation panel, then shuttle ADDRESS_ID from the Available Columns list to the Selected Columns list.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 9/40

    Click OK.

    10. In the Component Palette, select the Foreign Key component . In the diagram, click the top of the PERSONS table, thenclick the top of the ADDRESSES table to create the foreign key.

    11. In the Create Foreign Key dialog, accept the default foreign key properties and click OK.

    12. The diagram should now look like the following:

    The Create Foreign Key dialog lets you edit the default foreign key properties.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 10/40

    Notice the Primary, Foreign keys and indexes displayed in the tables.

    13. The Application Navigator should look like the following:

    14. Click Save All to save your work.

    Step 4: Create an Offline Database View

    Views are virtual tables based on the result-set of a SELECT statement that lets you combine tables and present the data as if the data werecoming from a single table. You can add SQL Functions, Joins, WHERE, GROUP BY, ORDER BY, or HAVING clauses to a view, to presentexactly the data you want to the user.

    1. From the Component Palette, drag and drop the View component onto the diagram. Then change the view name toPERSON_INFO.

    2. In the diagram, double-click PERSON_INFO to open the Edit View dialog and then select FROM clause in the navigation panel.

    In the Application Navigator, the PERSONS and ADDRESSES tables are displayed in the Offline Database Sources node.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 11/40

    3. Expand ADDRESES | ADDRESSES_PERSONS_FK in the Available list, and select PERSONS, then shuttle it to the Selected list tocreate a join between ADDRESSES and PERSONS.

    4. Select the JOIN node in the Selected list, and then click Edit .

    5. In the Edit Join dialog, accept the default JOIN, which is created using the Foreign Key, and click OK.

    Click OK again to close the Edit View dialog.

    6. In the database diagram, select All the columns except PERSON_ID in the PERSONS table. Then drag and drop them onto PERSONSview.

    You can create a JOIN in the Edit View dialog; once the JOIN node is selected, the Edit button is available.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 12/40

    7. In the diagram, select All the columns except PERSON_ID in the ADDRESSES table. Then drag and drop them onto ADDRESSES view.

    8. The database diagram now includes the offline database view:

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 13/40

    9. Click Save All to save your work.

    Step 5: Add a Sequence to a Diagram

    A sequence is a schema object that can generate unique sequential values. These values are often used for primary and unique keys. One wayto populate a key with a value from a sequence is to use a trigger to insert the sequence's NEXTVAL into the field.

    1. In the Application Navigator, under Offline Database Sources | DBOffline1 | DBDEMO, double-click PERSONS to open the Edit Tabledialog.

    2. Click Column Sequences in the navigation panel. Confirm that PERSON_ID is selected in the Column dropdown list.

    The database diagram now includes the offline database view:

    You use the Edit Table dialog to specify that you want to have the primary key for the table populated from a new sequence and updated viaa new trigger.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 14/40

    3. Select Populate Column from a Sequence on insert check box.

    Click OK.

    4. PERSONS_TRG trigger and PERSONS_SEQ sequence appear in the Application Navigator.

    5. In the Application Navigator, select the PERSONS_SEQ node then drag and drop it onto the diagram.

    In the Edit Table dialog, selecting Populate Column from a Sequence on insert on a column creates a default sequence for thatcolumn, and an associated trigger.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 15/40

    6. In the Component Palette, select the Dependency component. In the diagram, click the PERSONS table, then click thePERSONS_SEQ sequence to create the relationship.

    7. Click Save All to save your work.

    8. The offline database diagram and Application Navigator display the new sequence and trigger you created.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 16/40

    Step 6: Create a Table with Partitions

    If you have been following along with the example, the database objects created emulate an Oracle 11g database. If you have created objectsthat emulate another database type, for example an Oracle XE database, you may not be able to create partitions in a table.

    1. In the Application Navigator, under Offline Database Sources, right-click the DBOffline1 node, and choose New Data base ObjectNew Table.

    2. In the Create Table dialog, enter ORDERS as the table name, and select Advanced to display additional options. You should see adefault column ( COLUMN1) populated in the Columns list.

    3. Under Column Properties, change the name to ORDER_ID, then select NUMBER from the Type dropdown list.

    You can edit the sequence (for example, set the increment, minimum and maximum values) by double-clicking PERSONS_SEQ inthe Application Navigator to open the Edit Database Sequence dialog.

    Partitioned tables allow the data to be broken down into smaller, more manageable pieces called partitions, that can aid performance.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 17/40

    4. Click Add three times to add three more default columns. Then change the names and types to the following values: ORDER_DATE(type DATE), ORDER_TOTAL (type NUMBER), PERSON_ID (type NUMBER).

    5. In the navigation panel, select Primary Key, and shuttle ORDER_ID from the Available list to the Selected list.

    6. In the navigation panel, select Foreign Keys and click Add to add a new foreign key.

    7. Choose PERSONS from the Referenced Table dropdown list.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 18/40

    8. Confirm that PERSON_ID is selected in the Local Column dropdown list.

    9. In the navigation panel, select Partitioning, and select RANGE from the Partition By dropdown list.

    10. Shuttle ORDER_DATE from the Available list to the Selected list.

    You can choose from any of the schemas that you have referenced in your project to create foreign keys between tables in differentschemas.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 19/40

    11. In the navigation panel, select Partition Definitions and click Add .

    12. In the Partition Details section, enter ORDERS_PRE_2007 for the name and TO_DATE('01/01/2007', 'MM/DD/YYYY') for the values.

    13. Click Add to add a second partition definition. Enter ORDERS_2007 for the name and TO_DATE('01/01/2008', 'MM/DD/YYYY') for thevalues. .

    Click OK.

    14. Click Save All to save your work.

    15. The Application Navigator displays the new ORDERS table that was created:

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 20/40

    16. From the Application Navigator, drag ORDERS onto the diagram.

    Notice that since you defined a Foreign Key between Orders and Persons in the Edit Table Properties dialog, it is automatically drawn onthe diagram when you drop the Orders table.

    Step 7: Create a Database User and a Database Connection

    You can connect to any database for which you have connection details. If you can connect as a user with DBA privileges, follow the steps inthis card to create an IDE database connection and then create a new database user with the name DBDEMO.

    1. From the main menu, select File | New to open the New Gallery. Select General | Connections | Database Connection.

    Range, Hash, List, Composite Range-Hash and Range-List partitioning is supported for both tables and indexes.

    If you don't have DBA privileges, ask your DBA to create a DBDEMO database user with the Roles and System privileges as specified inthe following steps, and give you the password and connection details.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 21/40

    Click OK.

    2. If you can connect as a user with DBA privileges, follow steps 3 through 14 to create an IDE database connection and then create a newdatabase user with the name DBDEMO. If you don't have DBA privileges, ask your DBA to create a DBDEMO database user with theRoles and System privileges as specified in this tutorial. Then proceed to step 16 to create a DBDEMO connection.

    3. In the Create Database Connection dialog, select IDE Connections if it is not selected as the Create Connection In option.

    4. Enter a name for the connection TutorialConn and select the connection type. Then enter your username and password for connectingto the database. You must have DBA privileges if you (and not your DBA) will be creating a new database user. Select the JDBC Driver,and enter the Host Name, SID or Service Name, and JDBC Port . If you're not sure what driver to use, accept the default ( thin).

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 22/40

    5. Click Test Connection to confirm that you can connect.

    Click OK if the connection was successful.

    6. From the View menu option, choose Database --> Database Navigator.

    7. Expand the IDE Connections node and the TutorialConn connection node you created.

    8. Right-click the Other Users node and choose Create User.

    When you create the IDE database connection, the Database Navigator should look similar to this, when you expand the IDEConnections node:

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 23/40

    9. In the Create/Edit User dialog, enter DBDEMO as the name for the new user, then enter a password and confirm it.

    10. Click the Roles tab and select Granted for the following roles: CONNECT, RESOURCE.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 24/40

    11. Click the System Privileges tab and select Granted for the following roles: ALTER ANY SEQUENCE, ALTER ANY TABLE, COMMENTANY TABLE, CREATE ANY INDEX, CREATE ANY SEQUENCE, CREATE ANY TABLE, CREATE ANY TRIGGER, CREATE ANY VIEW.

    12. Click the SQL tab and review the SQL script to create the new user, then click Apply .

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 25/40

    13. Review the results of the SQL execution.

    Click Close.

    14. From the Main menu, select File | New. In the New Gallery, select General > Connections > Database Connection again to create aDBDEMO connection for the DBDEMO user you added earlier.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 26/40

    Click OK.

    15. Create a DBDEMO connection for the DBDEMO user you added earlier. Enter DBDEMOConn as the connection name, and DBDEMO forthe user name. Then enter the password and connection details. (If your DBA created the DBDEMO user, get the password andconnection details from your DBA.). Click Test Connection to confirm that you can connect.

    Click OK if the connection was successful.

    16. Click Save All to save your work.

    Step 8: Generate a DDL Script

    You can use JDeveloper to generate DDL for any offline objects you have created. You can choose the objects to include, whether you needCREATE, REPLACE or ALTER keywords, and other options for the DDL. You can choose to generate the DDL straight into a specific databaseor to generate a .sql script, using the Generate SQL from Database Objects wizard.

    1. In the Application Navigator, under Offline Database Sources | DBOffline1, right-click the DBDEMO node, and choose Generate tolaunch the Generate SQL from Database Objects wizard.

    2. On step 1, make sure Source from project is selected. Click Next .

    When you create the DBDEMO database connection, the connection is now included as a resource for your application in theApplication Resources panel of the Application Navigator.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 27/40

    3. On step 2, confirm that SQL Script is selected. Click Next.

    4. On step 3, shuttle the offline database objects from the Available list to the Selected list. Then click Next .

    5. On step 4, confirm that CREATE is selected. Then click Finish to generate the DDL script.

    If you have been following along with the example, the database objects created emulate an Oracle 11g database, and you canshuttle all the offline database objects to the Selected list.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 28/40

    6. The script1.sql file opens in the editor.

    7. In the editor window, click the SQL Worksheet bottom tab.

    8. In the SQL Worksheet, select the connection DBDEMOConn from the dropdown list on the right of the toolbar.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 29/40

    9. Click Run Script and review the output displayed.

    10. In the SQL Worksheet toolbar, click Commit.

    You can use the SQL Worksheet to enter and execute SQL, PL/SQL and SQL*Plus statements.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 30/40

    11. From the main menu, choose View | Database -->Database Navigator to open the Database Navigator. Click the Refresh button.

    12. Fully expand the DBDEMO node and its subnodes to see the new database objects.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 31/40

    Step 9: Reconcile the Database

    A powerful function of JDeveloper is the ability to compare offline database object definitions with live database objects. You can visually compareeach change and choose to either generate that change to the database in the form of an ALTER script, or live to the database.

    1. In the Application Navigator, under Offline Database Sources | DBOffline1 | DBDEMO , double-click the ADDRESSES node to open theEdit Table dialog.

    2. Click Add to add a new default column. Then change the name to TOWN and the size of type VARCHAR2 to 25. Then click OK.

    3. In the Application Navigator, double-click the PERSONS node to open the Edit Table dialog.

    When you run the SQL script, the output displays in the Script Output page of the SQL Worksheet:

    You will use the Edit Table dialog to make changes to your previously created offline objects and compare those changes to the live versionof the objects in the database.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 32/40

    4. In the Columns list, select GENDER and then select Cannot be NULL.

    5. In the Comment box, enter a 3 way flag (M)ale (F)emale (D)eclined to answer.

    Click OK.

    6. In the Application Navigator, under Offline Database Sources, right-click the DBOffline1 node, and choose Generate to launch theGenerate SQL from Database Objects wizard.

    7. On step 1, make sure Source from project is selected. Click Next .

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 33/40

    8. On step 2, confirm that SQL Script is selected. Click Next .

    9. On step 3, shuttle PERSONS and ADDRESSES from the Available list to the Selected list. Then click Next .

    10. On step 4, select ALTER and Manual Reconcile. Confirm that DBDEMO is the selected connection. Then click Next .

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 34/40

    11. On step 5, expand the PERSONS and ADDRESSES nodes to review the differences, which are highlighted in the left panel.

    12. Shuttle the differences to the online DBDEMO user on the right.

    13. Click Finish to generate the DDL script.

    Using ALTER and Manual Reconcile allows you to review the differences between the offline object definition and the object definitionin the database.

    By shuttling differences to the right panel you are specifying that these changes should be included in the DDL to be generated. Ifthere is any text that has been changed (such as the addition of the comment on the GENDER column in this example), highlightingthe text node will enable the Compare Text button so that you can compare the full text.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 35/40

    14. After completing the wizard, the new script script2.sql displays in the DBOffline1 node in the Application Navigator.

    15. The file opens in the SQL Worksheet source editor.

    16. Click Save All to save your work..

    Step 10: Reverse Engineer Database Objects

    In many application development projects, the starting point is an existing database. JDeveloper gives you the ability to reverse engineer anyexisting objects in the database into your application. From there you can edit, delete and create new offline definitions prior to generating newSQL scripts.

    1. Click the Application Navigator dropdown menu and select New Project from context.

    Another advantage of reverse engineering from a database is the ability to visualize existing schemas in a diagram.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 36/40

    2. In the New Gallery, select General | Projects | Database Project.

    3. Enter DBRevEng as the project name.

    Click Finish .

    4. In the Application Navigator, right-click the DBRevEng project and select New from context.

    5. In the New Gallery, select Database Tier | Offline Database Objects| Copy Database Objects to a Project.

    Click OK.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 37/40

    6. On step 1 of the Copy Database Objects to a Project dialog, confirm that the application connection you created earlier, DBDemoConn,is selected in the dropdown list.

    Click Next.

    7. On step 2, click the New button to the right of the Offline Database field to create a new offline database.

    8. Enter DBDemoReverse as the name and DBDEMO as the default schema.

    Click OK. Then click Next.

    9. On step 3, click Query to display all available database objects. Then shuttle the database objects from the Available list to the Selectedlist.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 38/40

    Click Next and then click Finish to generate the database objects.

    10. The generated objects are displayed in the Application Navigator.

    You will create a new database diagram and add the generated objects to the new diagram.

    11. In the Application Navigator, right-click the DBRevEng project and select New from context.

    12. In the New Gallery, select Database Tier | Offline Database Objects | Database Diagram.

    Click OK.

    13. Enter DBOffline2 as the diagram name, and confirm that oracle is entered as the package name.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 39/40

    Click OK.

    14. In the Application Navigator, select all the generated objects that have been reverse engineered into the project (except the trigger onethat doesn't display on a database diagram) then drag and drop them onto the diagram.

    15. The new database diagram shows the reverse-engineered objects, which were generated into the project and then dragged onto thediagram.

    An alternative way to achieve the same end result.

  • 3/5/2014 Oracle JDeveloper 11g Release 2 Tutorials - Designing and Building Database Tables

    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_84/jdtut_11r2_84.html 40/40

    16. Click Save All to save your work.

    You've successfully performed this tutorial.

    Summary

    In this tutorial you used JDeveloper to:

    Create a database diagram and add offline database tables

    Create offline database views

    Add a sequence to the diagram

    Create a table with partitions

    Create a database user and a database connection

    Generate a DDL script

    Reconcile the database

    Reverse-engineer database objects

    To learn more about database development, refer to:

    Using Logical Models in UML for Database Development

    "Getting Started with Working with Databases" in User's Guide for Oracle JDeveloper

    Copy right 2011, Oracle and/or its af f iliates. All rights reserv ed.