Lecture 1 Examples
Lecture 1 Examples
Database
Lecture 1 Examples
Topics: Data & Information, Why Databases?, Types of
DB, Relational DB, Data Modeling, Tables, Keys (PK,
FK, CPK, secondary key, candidate key)
2
Example 1: Data & Info
System: Retail Store
Objects: products, customers, employees, etc.
Data: products → TVs, cell phones, computer, etc.
customers → name, address, etc.
Info: products → best selling products, inventory
level of products, Products out of
stock
customers → demographics (aggregate data for
privacy)
4
File System: Examples and Complexities
Example 2 Envelope with Business Cards
Using an envelope of business cards is useful as long as it
doesn’t contain too many cards.
You can find a particular piece of information (for example, a
person’s phone number) by looking through all of the cards.
The envelope is easy to expand by shoving more cards into the
envelope, at least up to a point. If you have more than a dozen
or so business cards, finding a particular card can be time
consuming.
You can even rearrange the cards a bit to improve performance
for cards you use often. Each time you use a card, move it to
the front of the pile. Over time, those that are used most will
be in front.
5
File System: Examples and Complexities
Example 3 Paper Notebook with data
A paper notebook is small, easy to use, easy to carry, doesn’t
require electricity, and doesn’t need to boot before you can use it.
A paper notebook is also easily extensible because you can buy
another notebook to add to your collection when the first one is
full.
However, a notebook’s contents are arranged sequentially.
If you want to find information about a particular topic, you’ll
have to look through the pages one at a time until you find what
you want.
The more data you have, the harder this kind of search
becomes. 6
File System: Examples and Complexities
Example 4 Filing Cabinet System
A filing cabinet can store a lot more data than a notebook and
you can easily expand the system by adding more files or
cabinets.
Finding a particular piece of data in the filing cabinet can
be easier than finding it in a notebook as long as you are
searching for the type of data used to arrange the records.
If the filing cabinet is full of customer data sorted by
customer name, and you want to find a particular customer’s
data, you’re in luck.
If you want to find all of the customers that live in a certain
city, you’ll have to dig through the files one at a time.
7
What’s the difference between a database
and a spreadsheet?
10
Other Types of Databases
Many other database models exist that provide different strengths
than the relational model.
The most interesting new development is the concept of NoSQL (from
the phrase “not only SQL”).
A NoSQL database can work with data in a looser way, allowing for a
more unstructured environment, communicating changes to the data
over time to all the servers that are part of the database.
The relational database model is the most used database model today
and that’s what we will stick to in this course
Records/Rows/Tuples
12
Data Modeling for a DB
The data model for a DB is as follows:
Data Model (DB)
Row 1 …. Row n
Attribute 1 …. Attribute n
13
Goals of Effective Database Design
Using modern database tools, just about anyone can build a
database. The question is, will the resulting database be useful?
15
Example 6: Identifiers (Keys) of DB Tables –
Primary/Foreign Key
[include in different table]
employee
PK employee_id employee_first_ employee_last_ employee_phone employee_address
name name
Must be
Unique 100 Roger Shah 000-999-2323 Apt 1, X Ave, Boston,
MA
address
FK employee_id address_id address_1 address_2 address_city address_stat address_zip
17 e
100 1001 Apt 1 X Ave Boston MA 02115
Identifiers (Keys) of DB Tables
18
Example 7: Identifiers (Keys) of DB Tables –
Secondary/Candidate Key
employee
Secondary keys Candidate key
Web-based:
https://www.quackit.com/database/tutorial/
https://en.wikipedia.org/wiki/Comparison_of_relational_database_managem
ent_systems
20