com
Session 1
Oracle Concepts
to Identify
to Explain
to Plan
to Administer
to Monitor to Decide
to Analyze
to Implement
Graphics
Document
Spreadsheet
Table Database
WHAT IS DATABASE?
Data
Anything meaningless.
Meaningful arrangement of data.
Information
Database
Data Redundancy Data Inconsistency Difficulty in Accessing Data Data Isolation Integrity Problems
Atomicity Problem
Concurrent Access anomalies
Security Problems
What is a DBMS??
Database
A003 Allen A007 Shane
A008
Ricky
Update Data Delete Data
DBMS
Benefits of DBMS
The amount of redundancy in the stored data can be reduced No more inconsistencies in data The stored data can be shared Standards can be set and followed Data integrity can be maintained Security of data can be implemented
www.agogueconsultancy.com
Database Models
- Flat file model
- Hierarchical model - Network model - Relational model
RDBMS
Relational Database RDBMS A suite of S/W programs to create, maintain DB
Users of RDBMS
Database Administrators
End Users
Application Programmers
A Property
Relationship
Entity Attribute
Relationship
6/1/11
Attributes
Simple and composite attributes. Single-valued and multi-valued attributes E.g. multivalued attribute: phone-numbers Derived attributes Can be computed from other attributes E.g. age, given date of birth Example: customer = (customer-id, customer-name, customer-street, customer-city) loan = (loan-number, amount)
6/1/11
Relationship Sets
Relationship set : A mathematical relation among n 2 entities, each taken from entity sets
{(e1, e2, en) | e1 E1, e2 E2, , en En}
where (e1, e2, , en) is a relationship
Example:
6/1/11
6/1/11
Relationship Sets
6/1/11
Mapping Cardinalities
Express the number of entities to which another entity can be associated via a relationship set.
One to one
One to many Many to one
Many to many
6/1/11
Mapping Cardinalities
One to one
One to many
6/1/11
Note: Some elements in A and B may not be mapped to any elements in the other set
Mapping Cardinalities
Many to one
6/1/11
Many to many
Note: Some elements in A and B may not be mapped to any elements in the other set
6/1/11
E-R Diagrams
6/1/11
6/1/11
Roles
6/1/11
Cardinality Constraints
A customer is associated with at most one loan via the relationship borrower A loan is associated with at most one customer via borrower
6/1/11
Types of Relationships
1
Ha s 1 C_Code
Customer
N
Contain s
Order
Item
One-To-Many Relationship
6/1/11
Many-To-One Relationships
In a many-to-one relationship a loan is associated with several (including 0) customers via borrower, a customer is associated with at most one loan via borrower
6/1/11
Many-To-Many Relationship
6/1/11
6/1/11
6/1/11
Keys
Super key
candidate key primary key.
Unique key
Foreign key
6/1/11
We depict a weak entity set by double rectangles. We underline the discriminator of a weak entity set with a dashed line. payment-number discriminator of the payment entity set Primary key for payment (loan-number, payment-number)
6/1/11
In a university, a course is a strong entity and a course-offering can be modeled as a weak entity The discriminator of course-offering would be semester (including year) and section-number (if there is more than one section) If we model course-offering as a strong entity we would model course-number as an attribute. Then the relationship with course would be implicit in the coursenumber attribute
6/1/11
6/1/11
6/1/11
Question
Draw an ERD to show the relationship between the Orders and Item entities
Identifies
Database Designer Attributes Fields Relations
Relationships
Points to Note
Well defined relationship between tables Unnecessary or redundant data kept away.
Trick Id(pk)
Trick Name Trick Where Learned Skill Level
Puppy Number Puppy Name Kennel Code Kennel Name Kennel Location
Puppy Number Trick ID Trick ID Trick Name Trick Where Learned Skill Level
Puppy Tricks Puppy Number Trick ID Trick Where Learned Skill Level
Trick Trick ID Trick Name
All fields must contain small data There must be no repeating fields
Each table must contain information about a single entity
Denormalisation
Normalization has some drawbacks. Joins with multiple tables affects the performance of the database. The CPU time required to solve such queries will be very large. In such cases, storing a few fields redundantly can be considered to increase the performance of the database. Such a database is said to be a
www.agogueconsultancy.com
Denormalised database.
Features of tables
Each table must have unique name Each row in the table must be unique and describe one set of related information about the subject of the table. Each column or field describes a single characteristic of an entity. Column name must be unique within the table. The order of rows or columns is not significant.
www.agogueconsultancy.com
Keys
Default values Indexes
www.agogueconsultancy.com
Null values
Creating Tables
Modifying Tables
Add Rows
INSERT [INTO] <Table_name> VALUES <values>
Update Rows
UPDATE <Table_name> SET <Column_name = Value> WHERE <Search_Condition>
Delete Rows
DELETE FROM <Table_name> WHERE <Search_Condition>
Removing tables
Syntax :
DROP TABLE <table name>
Example :
DROP TABLE passenger
Joins
joins are used to query data from two or more tables.
A primary key is a column (or a combination of columns) with a unique value for each row.
Each primary key value must be unique within the table. The purpose is to bind data together, across tables, without repeating all of the data in every table.
Types of Joins
Self Join Cross Join Inner Join Outer Join
Self Join
Join on the same tabel
Cross Join
Provides cartesion product
Inner Join
The INNER JOIN keyword return rows when there is at least one match in both tables.
LEFT JOIN
The LEFT JOIN keyword returns all rows from the left table, even if there are no matches in the right table. SQL LEFT JOIN Syntax
The RIGHT JOIN keyword returns all the rows from the right table, even if there are no matches in the left table.
What is View?
VIEWS are data objects a virtual table based on the result-set of an query statement contains rows and columns functions, WHERE, and JOIN statements can be used in views
www.agogueconsultancy.com
View Syntax
CREATE VIEW view_name AS
Ex:
CREATE OR REPLACE VIEW person_view AS
www.agogueconsultancy.com
Ex:
CREATE OR REPLACE VIEW person_two_titles_view AS
SELECT first_name, last_name, socsecno FROM person WHERE title_1 IS NOT NULL AND title_2 IS NOT NULL;
www.agogueconsultancy.com