Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Order Filling
Prog A Prog B
Invoicing System
Program-data dependence
Duplication of data
Limited data sharing
Lengthy development times
Excessive program maintenance
Many of these can be limitations of databases
when
Many separately managed databases
No control on metadata
Uncontrolled data duplication
THE DATABASE APPROACH
EMPLOYEE(Emp_ID,Name,Dept_Name,Salary)
RELATIONAL KEYS
1. Domain Constraints
2. Entity Integrity
3. Referential Integrity
4. Operational Constraints
DOMAIN CONSTRAINTS
Order
Pending_Order
Order_ID Product_ID Quantity
Product
Business rules
Strong Entity
Weak Entity
An entity type whose existence depends on
other entity type. DEPENDENT
E-R MODEL SYMBOLS
Relation ship
Associative Entity
STUDENT: Student_ID,Student_Name
AUTOMOBILE: Vehicle_ID, Color,
Initial capital followed by lowercase.
If it has two words, underscore is used to connect
the words a each word starts with a capital letter
ATTRIBUTES
FLIGHT
E-R MODEL SYMBOLS
Multi-valued attribute
EMPLOYEE SKILL
E-R MODEL SYMBOLS
Derived attribute
EMPLOYEE Years_Employed
E-R MODEL
Degree of Relationship
Unary Relationship
One-to-many
EMPLOYEE Manages
DEGREE OF RELATIONSHIPS
Binary Relationship
One-to-one
One-to-many
Many-to-many
DEGREE OF RELATIONSHIPS
Ternary Relationship
A simultaneous relationship among instances
of three entity types
CARDINALITY CONSTRAINTS
Supplie
s
CUSTOMER
SHIPMENT Includ
ITEMS
es
Submit
Used_i s
n
Request
PRODUCT
s PRODUCT
NORMALIZATION
The process of decomposing relations with
anomalies to produce smaller well-structured
relations.
Anomalies: Errors or inconsistencies that may
result when user attempts to update a table
that contains redundant data.
Well-structured relations contains minimal
redundancy and allows users to insert,
modify, and delete the rows in a table
without errors or inconsistencies.
TYPES OF ANOMALIES
Insertion anomaly
Modify anomaly
Deletion anomaly
INSERTION ANOMALY
EMPLOYEE
Emp_ID
Name
Dept_Name
Salary
Course_Title
Date_Completed
INSERTION ANOMALY
To insert a row in the EMPLOYEE, user must
supply both Emp_ID and Course_Title,
since these together make a primary key,
hence can not be null.
DDL Design
Define the database
CREATE Tables, Indexes Views
Establish foreign keys
Drop tables Maintenance
SQL Commands
DML
Load the database
INSERT data Implementation
UPDATE the database
Manipulate the database (SELECT)
SQL Commands
Implementation
DCL
Control the database
GRANT, ADD, REVOKE
Maintenance
DDL Commands
SELECT
PRODUCT_NAME,UNIT_PRICE,QOH,
UNIT_PRICE * QOH AS VALUE FROM
PRODUCT;
USING EXPRESSIONS
Result:
PRODUCT_NAME UNIT_PRICE QOH VALUE
3 rows selected.
USING FUNCTIONS
Result:
Count(*)
2
RANGES
Query: Which products in the PRODUCT
table have unit price between 200 and 300?
SELECT
PRODUCT_NAME,UNIT_PRICE
FROM PRODUCT WHERE UNIT-
PRICE > 200 AND UNIT_PRICE < 300;
RANGES
SELECT
PRODUCT_NAME,UNIT_PRICE
FROM PRODUCT WHERE UNIT-
PRICE BETWEEN 200 AND 300;
SELECT CUSTOMER_NAME,CITY,STATE
FROM CUSTOMER WHERE STATE IN
(‘AP’, ‘TN’, ‘MP’, ‘UP’, ‘JK’);
SORTING RESULTS
ORDER BY Displays results in a sorted
order.
Result:
STATE COUNT(STATE)
AP 2
JK 1
MP 1
TN 2
UP 1
HAVING CLAUSE
HAVING clause is similar to WHERE, but it
identifies groups that meet a criterion rather
than rows.
SELECT CUSTOMER.CUSTOMER_ID,
ORDER.CUSTOMER_ID, CUSTOMER_NAME,
ORDER_ID FROM CUSTOMER, ORDER
WHERE CUSTOMER.CUSTOMER_ID =
ORDER.CUSTOMER_ID;
SELECT CUSTOMER.CUSTOMER_ID,
CUSTOMER_NAME, ORDER_ID FROM
CUSTOMER, ORDER WHERE
CUSTOMER.CUSTOMER_ID =
ORDER.CUSTOMER_ID;
OUTER JOIN
A join in which rows that do not have matching
values in common columns are nevertheless
included in the table.
SELECT
CUSTOMER.CUSTOMER_ID,CUSTOME
R_NAME, ORDER_ID FROM
CUTOMER, ORDER WHERE
CUSTOMER.CUSTOMER_ID =
ORDER.CUSTOMERID (+);
OUTER JOIN
SELECT CUSTOMER_NAME,
CUSTOMER_ADDRESS FROM
CUSTOMER WHERE
CUSTOMER.CUSTOMER_ID =
(SELECT ORDER.CUSTOMER_ID FROM
ORDER WHER ORDER_ID = 6878);
SUBQUERIES
Query: Which customers have placed orders?
SELECT CUSTOMER_ID,
CUSTOMER_ADDRESS FROM
INVOICE WHERE ORDER = 7678;
Suggested references