You are on page 1of 18

UNIT 3 : DATABASES & SQL

Developed by : Ms. Nita Arora Kulachi Hansraj Model School Ashok Vihar

Relational Data Model


Concept of Domain Tuple Relation Primary Key, Alternate Key, Candidate key

Relational Algebra
Selection Projection Union Cartesian Product

Advantages of the DBMS Approach


The Database Approach Versus the Traditional File Processing Approach
Storing data in a non-redundant database improves consistency of data.
There is only one copy of each item of data.

Unproductive Maintenance avoided.


In file based systems, changes to file structure cause endless problems on maintenance (re-writing code). Using a DBMS, program access is through a limited view (using SQL).
Thus programs cant see minor changes to the database.

What is a database?
A database is a collection of related data elements
Tables (entities) Columns (fields or attributes) Rows (records)

Some of the Advantages of using a DBMS Sharing of data


Control of redundancy and thus Data consistency Improved data integrity Better data accessibility Representing complex relationships among data Enforcing integrity constraints Better security of data (as long as backup is perfect) More control over concurrency Better backup and recovery procedures Providing multiple interfaces Faster development of new applications Economy of scale

Some of the Disadvantages of using a DBMS High cost of Software


Hardware costs high due to software complexity Requirement for skilled staff Higher programming costs - greater skill required Slower processing of some applications Increased vulnerability (all your eggs in one basket) More difficult recovery (if disaster strikes)

DBMS Architecture
Usually taken to imply a three level architecture. The complexity of a large database is handled by a DBMS by providing three views of the data.
An internal view of how the data is stored and accessed A conceptual view of what data is available in the database. Local or external views which are a limited and simplified view of the database as suitable for a single application or group of associated applications.

Three Level Architecture


External Level
Logical Data Independence

View 1

View 2

View 3

View 4 etc.

Conceptual Level
Physical Data Independence

Conceptual Schema

Internal Level

Internal Schema

One of the fundamental aspects of the database approach using a DBMS is that, by providing levels of data abstraction, it hides complexity of data storage from users.

DIFFERENT DATA MODELS


Hierarchical Data Model Network Data Model Relational Data Model
Relational Model propounded by E.F.Codd

RELATIONAL DATA MODELS :


Relation Attribute / Field / Column Tuple / Record / Row Concept of Domain Concept of Degree Cardinality View

Terminology

RELATIONAL DATA MODELS :


Primary Key Candidate key Alternate key Foreign key

Terminology
(Contd.)

Relational Algebra
The relational algebra is a collection of operations on relations. Each operation takes one or more relations as operand and produces another relation as its result

Relational Algebra
Operations defined in relational algebra include :
Select Project Cartesian Product Union * Set difference * Set intersection * Natural join * Division

Note : * items not in syllabus

Select

Extracts specified tuples (rows) from a specified relation (table).

Project

Extracts specified attributes(columns) from a specified relation.

Join

Builds a relation from two specified relations consisting of all possible concatenated pairs, one from each of the two relations, such that in each pair the two tuples satisfy some condition. (E.g., equal values in a given col.)
A1 B1 A2 B1 A3 B2 B1 C1 B2 C2 B3 C3 (Natural or Inner) Join A1 B1 C1 A2 B1 C1 A3 B2 C2

Outer Join

Outer Joins are similar to PRODUCT -but will leave NULLs for any row in the first table with no corresponding rows in the second.

Outer Join A1 A2 A3 A4 B1 B1 B2 B7 B1 C1 B2 C2 B3 C3

A1 B1 C1 A2 B1 C1 A3 B2 C2 A4 * *

Join Items

Invoice # Part # Quantity 93774 3 10 84747 23 1 88367 75 2 88647 4 3 776879 22 5 65689 76 12 93774 23 10 88367 34 2
Cust #

Part # 1 2 3 4 5 6 7 8 9

Name Price Count Big blue widget 3.76 2 Small blue Widget 7.35 4 Tiny red widget 5.25 7 large red widget 157.23 23 double widget rack 10.44 12 Small green Widget 30.45 58 Big yellow widget 7.96 1 Tiny orange widget 81.75 42 Big purple widget 55.99 9
STREET2 Floor 12 CITY New York Phildelphia Cyberoid Nashua Middletown Sagrado Rivendell Orinda Suite 882 Compton STATE NY PA NY NH IN TX CA CA CA ZIPCODE 02111 03756 08645 09242 32467 78798 93456 94563 95328

COMPANY STREET1 Integrated Standards 1 Ltd. 35 Broadway 2 MegaInt Inc.

Invoice # Cust # 93774 84747 88367 88647 776879 65689

Rep # 3 4 5 9 2 6 1 1 2 1 2 2

3 Cyber Associates General 4 Consolidated Consolidated 5 MultiCorp Internet Behometh 6 Ltd. Consolidated 7 Brands, Inc. 8 Little Mighty Micro 9 SportLine Ltd.

34 Bureaucracy Plaza Floors 1-172 3 Control Elevation Cyber Assicates Place Center 35 Libra Plaza 1 Broadway 88 Oligopoly Place 3 Independence Parkway 34 Last One Drive 38 Champion Place

You might also like