2. Database Management System
Why do we need Databases
To Store Data
To Read Data
Update Data
Delete Data
Why buy expensive DBMS
Store information in Excel
3. Why use database system?
Database Management System
Benefits
Multi user access.
Fast Data Access - Optimized algorithms.
Can survive system CRASH - Disaster recovery.
Multistep operations - Transaction support.
Advance security features.
Data consistency – rules for data structure
Allows indexing
4. DBMS and Databases
Different Types of DBMS
Hierarchical Database
Object Oriented Databases
Network Databases
Relational Databases
Different DBMS available in the marketplace
SQL Server
Oracle
DB2
MySQL
Database & DBMS relationship
5. Data Storage
Data is stored in TABLES
All major business entities may have their own
tables
Customer
Supplier
Products
Orders
Columns defines type-of-data, length-of-data
Each row uniquely identifies a customer, product,
or suppliers.
6. Table Structure
Primary Key
Unique identifier for a
row
Must contain a value
Unique Key
Uniquely defines a row
Can be NULL.
Name Address Phone Income
Paul Milpitas 408-102-
1111
55,000
Sam Fremont 510-102-
2222
85,000
Paul San Jose 95,000
Cust ID
1001
1002
1003
7. Common Terminology
Name Address Phone Income
Table = Relation
Row = Tuple
Column = Attribute = Field
Cardinality = Number of tuples
Degree = Number of attributes
Domain = Set of legal values for an attribute, for example
Gender attribute may have two legal values male/female
10. Normalization
What is normalization?
Split tables using specific rules to reduce
redundancy and avoid anomalies
Splitting tables may result in a performance hit while
accessing data.
Aim is to strike a balance between performance and
redundancy.
Example –
Highly Normalized structure may be used for applications
involving lot of transactions and/or complex transactions –
banking systems
Read only type of applications need not be highly
Normalized - websites
11. Normalization – 1nf
1st Normal Form
A relation is in 1nf if every attribute is atomic (not a
set or list)
Ord ID Date Time Location Amt $ Items
100 1/1/11 00:30 D101 12.25 Milk, Bread, Eggs
101 2/1/11 06:30 D025 725.7
5
Juice, iPad
102 3/1/11 12:30 D107 5.00 Shampoo, Soap
103 4/1/11 01:30 D022 18.50 Ink cartridge
104 5/1/11 02:30 D101 25.00 Banana, Oranges,
Milk
12. Normalization – 1nf
Ord ID Item
100 Milk
100 Bread
100 Eggs
101 Juice
101 iPad
103 Shampoo
103 Soap
104 Banana
104 Orange
104 Milk
Ord ID Date Time Location Amt $
100 1/1/11 00:30 D101 12.25
101 2/1/11 06:30 D025 725.7
5
102 3/1/11 12:30 D107 5.00
103 4/1/11 01:30 D022 18.50
104 5/1/11 02:30 D101 25.00
Composite P-
Key
1st Normal Form
- Eliminate repeating groups in individual
tables.
- Create a separate table for each set of
related data.
- Identify each set of related data with a
primary key.
13. Normalization – 1nf
Name City Phones 1 Phone 2
Sam Fremont 510-200-3000 NULL
Tom Concord 925-373-1212 925-255-1010
Bob Milpitas 408-408-2121 408-233-4545
Name City
Sam Fremont
Tom Concord
Bob Milpitas
Name Phone
Sam 510-200-3000
Tom 925-373-1212
Tom 925-255-1010
Bob 408-408-2121
Bob 408-233-4545
14. Normalization
2nd Normal Form
A relation is in 2NF if every non-prime attribute is
non-partially dependent on the Primary Key.
Relation meets 1NF
R. No Course # Course Grade
R100 C001 Maths A
R101 C002 Chem B+
R101 C003 Physics C
18. Database Design
Common Design Patterns
Hierarchy
Master Detail
Registration
Lookups
Order
Common Flags
IsActive?
IsDeleted?
19. Data Access
DDL – Data Definition Language
Create, Alter, Drop, Truncate, Rename etc.
DCL – Data Control Language
Grant, Revoke
DML – Data Modification Language
Insert, Update, Delete etc.
DQL – Data Query Language
Select
20. SQL - Basic
Simple Selects (using single table)
Concept of ALIAS
Where Clause
Operators
21. SQL - Basic
Understand Grouping and Aggregation
Understand Having Clause
Difference between Having and Where
Understand NULL
Condition translates to Boolean true/false