Week 01 Notes 01

Installing MySQL on a Windows computer

See https://webpages.sou.edu/~nordquip/cs360/notes/mysql5.5.62Install2019.htm

Why databases

Eliminate duplicate data

What’s wrong with duplicate data?

Must make a single change in multiple places.

Introduces the possibility for inconsistency.

Wastes space.

Inefficient.

Minimize null values

What is a null value?

Missing data?  Default data?

What’s wrong with null values?

Their meaning is ambiguous.

 

Duplicate Data Problem Example

List an automobile manufacturer might create to tracking vehicles it would like to produce:

Model

Color

ManufacturingPlant

City

Qty

Camry

red

us1

detroit

150000

Camry

red

us2

Detroit

100000

Duplicate work – If I want to change the name of the model to camrey, I have to change two rows.

Inconsistencies – suppose I search for all autos to be manufactured in Detroit, row 1 will be missed.

Attributes for multiple entities in a single list – City is an attribute of ManufacturingPlant, it not an attribute of a car.  If plant us2 is moved to Houston, all records in this list having us2 as the manufacturing plant must change their city to Houston.

Relational Model

A relation is just a table with a few constraints that we’ll explore later.

A table holds data for a particular kind of thing (called a theme in chapter 1 of the text), e.g., Student.

 

So for our purposes at this moment, a relation, table, theme, entity are all the same thing.

 

Relational model developed by E.F. Codd and rooted in Logic.  Can think of a table as a set of propositions that are true, e.g., from the table above: there exists a type of car whose model is ‘Camry’ whose color is ‘red’ that is manufactured in the plant ‘us1’, which is located in the city ‘detroit’, and 150000 of these cars were manufactured there.

 

A table is a 2-dimensional array of values.

A row holds a set of values that describe a particular entity, e.g., a particular student.

A column holds a set of values for a particular attribute that all entities possess, e.g., all students have a name.

 

In java, a class defines the instance variables (attributes) for all objects instantiated (built) from this class?

 

A row in a table is analogous to a particular object built from a class in java.

Uniquely identifying entities having duplicate attribute data

Suppose we have a student table having one attribute – name.

We want to be able to support two students who have the same name.

 

In java, we create two separate objects, which produces two different references.

 

Create a ‘dummy’ attribute that causes all entities in the same table to be unique – studentID.

Actions

Data is manipulated in relational databases using Structured Query Language (SQL).  There are only 4 actions possible:

Insert

Add a row to a table

Update

Change a row that was already in a table

Delete

Remove a row from a table

Select

Retrieve a row(s) from a table(s).  We will concentrate on select for a while.

 

(MYSQL provides a graphical interface to insert, update, delete, and select from tables, but it can also be done with SQL statements.)

 

Select Syntax:

Select <fields> from <table_specifications> where <search conditions>

 

Table specifications will get a more complex, but for now, it is just the name of a table, e.g., student.

Simple <search conditions> compare a name with a value.

 

See the text pages mentioned in the course schedule for legal where-clause conditions.

 

Connecting to your database on webpages 

See connectToWebpagesUsingMySQLWorkbench.htm

 

Example

Initialize your webpages database with the tables needed for lab 1.

 

In MySQL Workbench, open another sql script window and type SQL to find:

1.     All data for all animals

2.     AnimalIDs of animals whose Name starts with ‘H’

 

Note on case sensitivity:  the behavior of queries w.r.t. case sensitivity depends on how the table was defined.  The pet store database we will see in lab was defined in such a way that searches are case insensitive.  Case sensitive searches can be forced by preceding the column name with keyword ‘binary’, e.g,

 

select *

from Animal

where binary name = ‘hunter’

 

selects all animals whose name is lowercase ‘hunter’ (there are none).

 

select *

from Animal

where name = ‘hunter’

 

selects all animals whose name is case-insensitive ‘hunter’ (there are three).