39
Managing Database With Oracle Replacement for Ch10 COP 4708

Managing Database With Oracle Replacement for Ch10 COP 4708

Embed Size (px)

DESCRIPTION

Starting With Oracle Click on Application Express to start working with Oracle

Citation preview

Page 1: Managing Database With Oracle Replacement for Ch10 COP 4708

Managing Database With Oracle

Replacement for Ch10COP 4708

Page 2: Managing Database With Oracle Replacement for Ch10 COP 4708

Introduction• Oracle is the world’s most popular DBMS - It is a powerful

and robust DBMS that runs on many different operating systems

• Oracle DBMS engine available in several versions:– The Personal Edition of Oracle (is available with this text and can

also be downloaded from Oracle)– Express Edition (the one that we downloaded and installed) – Standard Edition– Professional Edition

• Example of Oracle products:– SQL*Plus: a utility for processing SQL and creating components like

stored procedures and triggers:• PL/SQL is a programming language that adds programming constructs to

the SQL language– Oracle Developer (Forms & Reports Builder)

Page 3: Managing Database With Oracle Replacement for Ch10 COP 4708

Starting With Oracle

Click on Application Express to start

working with Oracle

Page 4: Managing Database With Oracle Replacement for Ch10 COP 4708

Starting with Oracle

You will get a login screen where you enter your username (sys) and password (whatever the

password that you used during installing Oracle)

Page 5: Managing Database With Oracle Replacement for Ch10 COP 4708

Create User or Use Existing

Once you login you can create a new user workspace or use

existing workspace

Page 6: Managing Database With Oracle Replacement for Ch10 COP 4708

Oracle User Interface

Page 7: Managing Database With Oracle Replacement for Ch10 COP 4708

Creating Tables

Click on SQL Workshop, Object Browser, and from the Create Object Menu select Table

Page 8: Managing Database With Oracle Replacement for Ch10 COP 4708

Creating Table

Once you click on the create table tab you will get this screen

Fill in the name of the table as ARTIST from the View Ridge Gallery Database

Fill in the different columns needed as indicated in the following slide

Page 9: Managing Database With Oracle Replacement for Ch10 COP 4708

ARTIST Table

Column Name Column Type Size NULL

ArtsitID Number (38,1) No

Name Char 25 NoNationality Varchar2 30 Yes

BirthDate Number (4,0) Yes

DeceasedDate Number (4,0) Yes

Page 10: Managing Database With Oracle Replacement for Ch10 COP 4708

ARTIST Table

Once you insert the column name, type size and the null constraint click next to choose a primary key for the table

Page 11: Managing Database With Oracle Replacement for Ch10 COP 4708

Primary Key

Select Not Populated since you will entering the values your self. Then select the primary key to be ArtistID and click Next twice to skip Foreign Key setup to constraints

Page 12: Managing Database With Oracle Replacement for Ch10 COP 4708

Adding Constraint

You can choose the type of constraint whether Check or Unique

The name of the constraint will be created Automatically

Page 13: Managing Database With Oracle Replacement for Ch10 COP 4708

Adding Constraints

• Check Constraints:– (Nationality In ('Canadian', 'English', 'French',

'German', 'Mexican', 'Russian', 'Spanish', 'US'))– (BirthDate < DeceasedDate)– (Birthdate > 1000) and (Birthdate < 2100)– (DeceasedDate > 1000) and (DeceasedDate <

2100)• Unique Constraint:

– Name

Page 14: Managing Database With Oracle Replacement for Ch10 COP 4708

Adding Constraints

This is a snapshot of all the constraints that have been added. You will have 4 check and one unique

Click Finish then confirm the table creation by clicking on Create

Page 15: Managing Database With Oracle Replacement for Ch10 COP 4708

Table Manipulation The table has been created

You can Drop (Delete) the table by clicking on Drop, or You can rename the table by clicking on Rename

You can Add a new column

You can modify an existing column

You can rename a column

You can drop a column

Page 16: Managing Database With Oracle Replacement for Ch10 COP 4708

Table Manipulation Exercise

• Add a column called MyColumn with a data type char (20)

• Rename that column to ArtistAge • Modify the data type to be Number (5,0)• Drop that column

Page 17: Managing Database With Oracle Replacement for Ch10 COP 4708

Inserting Data Into Table

To insert data into table click on the Data tab then click Insert Row

Page 18: Managing Database With Oracle Replacement for Ch10 COP 4708

ArtistID Name Nationality BirthDate DeceasedDate

3 Miro Spanish 1870 1950

4 Kandinsky Russian 1854 1900

5 Frings US 1950 Null

6 Klee German 1900 Null

8 Moos US Null Null

14 Tobey US Null Null

15 Matt French Null Null

16 Chagall French Null Null

Insert Data into table then click Create and Create Another

Use the information provided here

After the last entry click Create tab

Page 19: Managing Database With Oracle Replacement for Ch10 COP 4708

Table Including Data

You should be able to have the table with all data inserted as shown in the figure

You can count the number of rows in the table or you can insert more records (rows of data)

Click on SQL

Page 20: Managing Database With Oracle Replacement for Ch10 COP 4708

SQL Code For Artist TableCREATE TABLE "ARTIST" ( "ARTISTID" NUMBER(38,1) NOT NULL, "NAME" CHAR(25) NOT NULL, "NATIONALITY" VARCHAR2(30), "BIRTHDATE" NUMBER(4,0), "DECEASEDDATE" NUMBER(4,0),

CONSTRAINT "ARTIST_PK" PRIMARY KEY ("ARTISTID"), CONSTRAINT "ARTIST_CK1" CHECK ((Nationality In ('Canadian',

'English', 'French', 'German', 'Mexican', 'Russian', 'Spanish', 'US')),

CONSTRAINT "ARTIST_CK2" CHECK ((BirthDate < DeceasedDate)),

CONSTRAINT "ARTIST_CK3" CHECK ((Birthdate > 1000) and (Birthdate < 2100)),

CONSTRAINT "ARTIST_CK4" CHECK ((DeceasedDate > 1000) and (DeceasedDate < 2100) ),

CONSTRAINT "ARTIST_UK1" UNIQUE ("NAME") )

This is the automated code that has been created by the system

Page 21: Managing Database With Oracle Replacement for Ch10 COP 4708

Exercise

• Create WORK table using the following Information

Column Name Column Type Size NULL

WorkID Number (38,1) No

Title Varchar2 25 NoDescription Varchar2 1000 Yes

Copy Varchar2 8 Yes

ArtistID Number No

Page 22: Managing Database With Oracle Replacement for Ch10 COP 4708

Exercise (Cont.)

• Assign a primary key• Assign a foreign key remember to add the

reference table as ARTIST and the reference column

• Add the following constraints:– Title, copy as unique

Page 23: Managing Database With Oracle Replacement for Ch10 COP 4708

Exercise (Cont.)• Then insert the following information:

WorkID Title Description Copy ArtistID

505 Mystic Fabric Opposite meaning 99/135 14

506 Mi Vida Dark background 7/100 3

507 Slow Embers From the artist’s originals HC 14

525 Mystic Fabric Some water damage 105/135 14

530 Northwest By Night Wonderful, moody 37/50 16

Page 24: Managing Database With Oracle Replacement for Ch10 COP 4708

Work Table Created with Data

You should be able to get the table shown in the figure with populated rows

Click on Model

Page 25: Managing Database With Oracle Replacement for Ch10 COP 4708

Database Model

Oracle screen that shows the conceptual model of the database and the relation between the ARTIST table and the WORK table

Page 26: Managing Database With Oracle Replacement for Ch10 COP 4708

Table Dependencies

When you click on Dependencies the system will list the tables that the WORK table depends on

Now click on Create to create a View

Page 27: Managing Database With Oracle Replacement for Ch10 COP 4708

Creating View

In the view name enter ArtistNameView

Then write the SQL code to create the view in the query box

Page 28: Managing Database With Oracle Replacement for Ch10 COP 4708

Viewing and Manipulating the View

The view will be created

To look at the view or the query that you created click on Data and you will see this table with artists’ names

CREATE OR REPLACE FORCE VIEW "ARTISTNAMEVIEW" "ARTISTNAME") AS

Select Name as ArtistName

From ARTIST

When click on SQL you will get the code for creating the view including the query

You can click on Drop to delete the view

Page 29: Managing Database With Oracle Replacement for Ch10 COP 4708

Utilities

So we used the Administration tab, the object browser tab, the SQL tab, how about utilities? Click on utilities then select Data

Load/Unload then select load

Page 30: Managing Database With Oracle Replacement for Ch10 COP 4708

Utilities

Select Load Spreadsheet Data and you will get this screen

Select New Table

Select Upload File

Page 31: Managing Database With Oracle Replacement for Ch10 COP 4708

Spreadsheet file

• Before you upload the file to Oracle open your Excel sheet that has the table

• Click save as• Keep the file under the same name in our

case will be (Customer Table)• Select Save as type (Text (Tab delimited)

(*.text) then save

Page 32: Managing Database With Oracle Replacement for Ch10 COP 4708

Uploading Data from Spreadsheet

Browse to the txt file that you just saved then set separator \t for tab

Click Next

Page 33: Managing Database With Oracle Replacement for Ch10 COP 4708

Creating Table In The Database

Name the table as CUSTOMER

All columns been loaded and data type been recognized

Page 34: Managing Database With Oracle Replacement for Ch10 COP 4708

Creating Customer Table

To setup the primary key select use an existing column and choose Customer_ID

Then select Not generated

Then Click Load Data

Page 35: Managing Database With Oracle Replacement for Ch10 COP 4708

Creating Customer Table

Table has been imported

To make sure of that go to the home page click Object Browser, browse for tables, you will see the customer table been created and if you click on Data you will see the table populated with data

Page 36: Managing Database With Oracle Replacement for Ch10 COP 4708

Customer Table with Populated Rows

Page 37: Managing Database With Oracle Replacement for Ch10 COP 4708

Generating Object Reports

Also under Utilities tab you can generate Object Reports that provides different reports about the objects included in the database, such as a report about the different columns, their type and their size

Page 38: Managing Database With Oracle Replacement for Ch10 COP 4708

Restoring Deleted Objects

Also You can retrieve or restore object that has been deleted by mistake by going to the Recycle Bin and choosing Dropped Objects

Then select from the list the object that you would like to restore

Page 39: Managing Database With Oracle Replacement for Ch10 COP 4708

Click on Restore Object

Restoring Deleted Objects