INTRODUCTION TO ORACLE
Lynnwood Brown
System Managers LLC
Application Development For DBA’s Lecture 8
Copyright System Managers LLC 2007 all rights reserved.
APPLICATION DEVELOPEMENT
Entity-Relationship Modeling
The ER model provides the framework for understanding how the application should be written.
• Models can be changed quickly
• Models show the alternatives to satisfying a business requirement
• Model can be used to estimate system capacity requirements
APPLICATION DEVELOPEMENT
ER modeling is a graphical technique for capturing business information and the relationships between the data. ER models consist of:
Entities - The things of significance about the information that is held. Entities often become the tables or views that a application will use
Relationships - Describe how the entities Rae related. The different types of relationships include one to one (1:1), one to many (1:M), many to one (M:1), many to many (M:M) and optional relationships.
Attributes - The specific information that describes the entity. Attributes often become the columns in the tables. An attribute can be mandatory (must always have a value - *), optional (can be NULL - o) or unique (#).
APPLICATION DEVELOPMENTER Model Components
E N T IT Y
one to one one to m any m any to m any
Type s of re la tio nship s:
- - - - - - - - - -op tional
Copyright System Managers LLC 2007 all rights reserved.
APPLICATION DEVELOPMENT One To One Relationships
Computer Motherboard- - - - - - -
Each computer must have one motherboard
Each motherboard may be put into one computer
Copyright System Managers LLC 2007 all rights reserved.
APPLICATION DEVELOPMENTOne To Many Relationships
S ales Representat ive Custom er- - - - - -
Each customer must be visited by only one sales representative.
A sales representative may be assigned one or more customers.
Copyright System Managers LLC 2007 all rights reserved.
APPLICATION DEVELOPMENT
My name is K.E. Nell. I am the owner and operator of KEN’s Kennel. At KEN’s Kennel we board pets while their owners are out of town. When the owner brings in their pet we obtain the name of the owner, the name of each pet, the age f each pet and the pets weight, species, gender, color and breed.
We also need information about the customer. We need their name, address,
home phone, their veterinarian’s name and phone number, and when they will be returning for the pet.
Each pet, I house in a very spacious kennel suite during his or her stay. The
larger pets reside in a 30 x 20 foot kennel and the smaller pets get a nice cozy 10 x 5 foot kennel suite. For the pets safety and comfort only one pet is placed into a kennel suite at a time.
Copyright System Managers LLC 2007 all rights reserved.
APPLICATION DEVELOPMENT
In the narrative we must first find the entities or “things of significance”. The characteristics of an entity include:
• An entity is an object of interest/significance to the business
• An entity is a noun• An entity is a category or class
Copyright System Managers LLC 2007 all rights reserved.
APPLICATION DEVELOPMENTER Model
Pe t#* ido ageo w e igh t* s pec ieso breedo c o lo ro g ender
Ke nn e l#* loc a tion* s iz e
Ow n e r#* id* name* p hone* v e ter inar ian name* v e ter inar ian p hone* re turn da te
- - - - - -- -
Copyright System Managers LLC 2007 all rights reserved.
APPLICATION DEVELOPMENTImplementing Business Rules
Business rules are implemented by using constraints. The different types of constraints include:
Primary Key Constraint – All column values must be unique and not null
Unique Constraint – All column values must be unique
Not Null Constraint – No column data can contain a NULL (a value must be supplied)
Foreign Key Constraint – The values of the column data in one table (child) must first exist in another table (parent)
Copyright System Managers LLC 2007 all rights reserved.
APPLICATION DEVELOPMENTImplementing Business Rules
Creating a primary key constraint Creating a primary key constraint at table creation time: SQL > CREATE TABLE EMP(EMPNO NUMBER PRIMARY KEY,ENAME VARCHAR2(20),…..); Creating a primary key constraint after the table has been created: SQL > ALTER TABLE EMP ADD PRIMARY KEY (EMPNO);
Copyright System Managers LLC 2007 all rights reserved.
APPLICATION DEVELOPMENTImplementing Business Rules
Creating a unique constraint Creating a unique constraint at table creation time: SQL > CREATE TABLE EMP(DEPTNO NUMBER,DEPT_NAME VARCHAR2(10) CONSTRAINT UN_NAME
UNIQUE,…); Creating a unique constraint after the table has been created: SQL > CREATE UNIQUE INDEX ON DEPT (DEPT_NAME);
Copyright System Managers LLC 2007 all rights reserved.
APPLICATION DEVELOPMENTImplementing Business Rules
Creating a not null constraint Creating a not null constraint at table creation time: SQL > CREATE TABLE EMP(EMPNO NUMBER,ENAME VARCHAR2(20) NOT NULL,…..); Creating a not null constraint after the table has been created: SQL > ALTER TABLE EMP MODIFY (SAL NUMBER
CONSTRAINT MY_EMP_CON NOT NULL;
Copyright System Managers LLC 2007 all rights reserved.
APPLICATION DEVELOPMENTImplementing Business Rules
Creating a foreign key constraint Creating a foreign key constraint at table creation time: SQL > CREATE TABLE EMP(EMPNO NUMBER,ENAME, VARCHAR2(20),..DEPTNO NUMBER CONSTRAINT FKEY_DEPT REFERENCES
DEPT(DEOTNO));
Copyright System Managers LLC 2007 all rights reserved.
APPLICATION DEVELOPMENTImplementing Business Rules
Creating a foreign key constraint
Creating a foreign key constraint after the table has been created:
SQL > ALTER TABLE EMP
ADD CONSTRAINT FKEY_DEPT
FOREIGN KEY (DEPTNO)
REFERENCES DEPT(DEPTNO);
Copyright System Managers LLC 2007 all rights reserved.
APPLICATION DEVELOPMENTImplementing Business Rules
Data Dictionary Constraint Views
The following data dictionary views are used to keep track of constraints that have been defined:
• DBA_CONSTRAINTS – Constraint definitions (OWNER, TYPE ETC…)
• DBA_CONS_COLUMNS – Name of the column in the constraint definition
Copyright System Managers LLC 2007 all rights reserved.
APPLICATION DEVELOPMENTEstimating Table Size
Table Field Sizes:
• Date fields = 7 bytes• Character fields = 1 byte per character• Number of bytes for numerical fields = precession/2 + 1
Create Table TEST(EMPNO NUMBER(4)ENAME VARCHAR2(15),HIRE_DATE DATE,SAL NUMBER(7,2));
Record Size = (4/2+1) + 15 + 7 + (7/2+1) = 28.5 bytes
APPLICATION DEVELOPMENTEstimating Tablespace Extent Sizes
Place like sized tables in their own tablespace:
• Small tables and indexes - 128 MB and smaller– Tablespace INITIIAL and NEXT Extent Size = 128KB
• Medium sized tables and indexes - 128MB to 4GB– Tablespace INITIIAL and NEXT Extent Size = 4MB
• Large tables and indexes - 4 GB and higher– Tablespace INITIIAL and NEXT Extent Size = 4MB
This is done to reduce tablespace fragmentation
Copyright System Managers LLC 2007 all rights reserved.
REPLICATION
Replication – Used to copy of one or more tables from one database to another.
• Simple Replication - One way replication using the SNAPSHOT feature
• Oracle Advanced Replication - Uses the Oracle supplied package DBMS_REPCAT to implement two way or master to master replication
• Uses the SNP background process on the primary machine to replicate the data to the secondary server
• Used to populate a report server or data warehouse
REPLICATION cont.
Simple Replication – Replication (secondary) site database setup to replicate the “emp” table:
• Create the snapshot (replicate the table):
SQL > create snapshot emp SQL > refresh fast SQL > start with sysdate SQL > next (sysdate+1) + 03/24 /* refresh every 24 hours.
at 3:00 AM */SQL > as select * from scott.emp@master_site_alias;
REFRESH = FAST – For Incremental table updatesREFRESH = COMPLETE – For a complete table update.
APPLICATION DEVELOPMENT
Summary:
• Use ER modeling to determine the applications base tables and the relationships between them
• Use database constraints to implement business rules
• Determine the amount of data that must be stored
• Size data and index tablespace extents according to the size of the objects that will be stored in them
Copyright System Managers LLC 2007 all rights reserved.
Top Related