This tutorial shows introduces Oracle SQL Developer and shows you how to manage your database objects.
Approximately 50 minutes
Oracle SQL Developer is a free graphical tool that enhances productivity and simplifies database development tasks. Using SQL Developer, users can browse database objects, run SQL statements, edit and debug PL/SQL statements and run reports, whether provided or created.
Developed in Java, SQL Developer runs on Windows, Linux and the Mac OS X. This is a great advantage to the increasing numbers of developers using alternative platforms. Multiple platform support also means that users can install SQL Developer on the Database Server and connect remotely from their desktops, thus avoiding client server network traffic.
Default connectivity to the database is through the JDBC Thin driver, so no Oracle Home is required. To install SQL Developer simply unzip the downloaded file. With SQL Developer users can connect to any supported Oracle Database, for all Oracle database editions including Express Edition.
Before starting this tutorial, you should:
- Install Oracle SQL Developer 2.1 early adopter from OTN here. Follow the readme instructions here.
- Install the Oracle Database 10g and later.
- Unlock the HR user. Login to SQL*Plus as the SYS user and execute the following command:
alter user hr identified by hr account unlock;
- Download and unzip the sqldev_mngdb.zip file that contains all the files you need to perform this tutorial.
The first step to managing database objects using Oracle SQL Developer is to create a database connection. Perform the following steps:
1 . | Open Oracle SQL Developer.
|
2 . | In the Connections navigator, right-click Connections and select New Connection.
|
3 . | Enter HR_ORCL for the Connection Name (or any other name that identifies your connection), hr for the Username and Password, specify your localhost for the Hostname and enter ORCL for the SID. Click Test.
|
4 . | The status of the connection was tested successfully. The connection was not saved however. Click Save to save the connection, and then click Connect.
|
5 . | The connection was saved and you see the database in the list.
|
6 . | Expand HR_ORCL.
Note: When a connection is opened, a SQL Worksheet is opened automatically. The SQL Worksheet allows you to execute SQL against the connection you just created.
|
7 . | Expand Tables.
|
8 . | Select the Table EMPLOYEES to view the table definition. Then click the Data tab.
|
9 . | The data is shown. In the next topic, you create a new table and populate the table with data.
|
You create a new table called DEPENDENTS which has a foreign key to the EMPLOYEES table. Perform the following steps:
Oracle SQL Developer makes it very easy to make changes to database objects. In this topic, you add a column to the DEPENDENTS table you just created. Perform the following steps:
1 . | Select the DEPENDENTS table.
|
2 . | Right-click, select Column then Add.
|
3 . |
Enter RELATIVE_ID, select NUMBER from the droplist, set the Precision to 6 and Scale to 0.
Click Apply.
|
4 . |
The confirmation verifies that a column has been added.
Click OK.
|
5 . | Expand the DEPENDENTS table to review the updates.
|
In this topic, you create the Primary and Foreign Key Constraints for the DEPENDENTS table. Perform the following steps:
1 . | Right-click DEPENDENTS table and select Edit...
|
2 . | Click the Primary Key node in the tree.
|
3 . | Select the ID column and click > to shuttle the value to the Selected Columns window.
|
4 . | Select the Foreign Key node in the tree and click Add.
|
5 . | Select EMPLOYEES for the Referenced Table and select RELATIVE_ID for the Local Column and click OK.
|
You can add data to the DEPENDENTS table by performing the following steps:
One way to access DEPENDENTS data is to generate a SELECT statement on the DEPENDENTS table and add a WHERE clause. Perform the following steps:
As the SQL you just ran in the previous topic needs to be executed frequently, you can create a custom report based on the SQL. In addition, you can run a report of your database data dictionary using bind variables. Perform the following steps:
Oracle SQL Developer contains extensive PL/SQL editing capabilities. In this topic, you create a Package Spec and Package Body that adjusts an employee's salary. Perform the following steps: