12
RDBMS MySQL

RDBMS MySQL. MySQL is a Relational Database Management System MySQL allows multiple tables to be related to each other. Similar to a Grandparent to a

Embed Size (px)

Citation preview

Page 1: RDBMS MySQL. MySQL is a Relational Database Management System MySQL allows multiple tables to be related to each other. Similar to a Grandparent to a

RDBMS

MySQL

Page 2: RDBMS MySQL. MySQL is a Relational Database Management System MySQL allows multiple tables to be related to each other. Similar to a Grandparent to a

MySQL

• MySQL is a Relational Database Management System

• MySQL allows multiple tables to be related to each other.

• Similar to a Grandparent to a parent, a parent to child and so forth.

Page 3: RDBMS MySQL. MySQL is a Relational Database Management System MySQL allows multiple tables to be related to each other. Similar to a Grandparent to a

Table Fields

• When you create a table make the first field an int, unsigned, auto increment and primary key– Ints are whole numbers– Unsigned are numbers that are positive only– Auto increment set the table to automatically add

a new number in this field every time a new record is added to the next available number

– Primary key means that the field is easily searched on and each record has a unique value.

Page 4: RDBMS MySQL. MySQL is a Relational Database Management System MySQL allows multiple tables to be related to each other. Similar to a Grandparent to a

Table Fields for Child Tables

• If you have a child table the second field should be a foreign key– Foreign key field names are based on the table

name and the field name• manufactuer_id

– The field type should be the same as the primary key of the parent table

– Index this field– Other fields should then follow.

Page 5: RDBMS MySQL. MySQL is a Relational Database Management System MySQL allows multiple tables to be related to each other. Similar to a Grandparent to a

Basic Flat table

A flat table with manufacturer, product and comments.

Basic until you start adding more data

Page 6: RDBMS MySQL. MySQL is a Relational Database Management System MySQL allows multiple tables to be related to each other. Similar to a Grandparent to a

Basic Flat table

More dataIssues with duplicate infoTable data sizes increases

Page 7: RDBMS MySQL. MySQL is a Relational Database Management System MySQL allows multiple tables to be related to each other. Similar to a Grandparent to a

Basic Flat table

Data may not be the same or inconsistent

Page 8: RDBMS MySQL. MySQL is a Relational Database Management System MySQL allows multiple tables to be related to each other. Similar to a Grandparent to a

Normalization

• The solution of not having a flat table with duplicate data and inconsistent information is to normalize the tables.

• That is to make multiple tables from the one where data is not duplicated.

Page 9: RDBMS MySQL. MySQL is a Relational Database Management System MySQL allows multiple tables to be related to each other. Similar to a Grandparent to a

Normalization

• Besides making the different tables you need to add the foreign keys

• Foreign key is a term for a field that is indexed and the values relate to another table.

Page 10: RDBMS MySQL. MySQL is a Relational Database Management System MySQL allows multiple tables to be related to each other. Similar to a Grandparent to a

Normalization

• Besides making the different tables you need to add the foreign keys

• Foreign key is a term for a field that is indexed and the values relate to another table.

Page 11: RDBMS MySQL. MySQL is a Relational Database Management System MySQL allows multiple tables to be related to each other. Similar to a Grandparent to a

The SQL call to retrieve this data is called a JOIN

• The type of JOIN we will be doing is a straight join using a WHERE clause

• The names of field now need to be proceeded with the table name.

• The table name and field is separated with a period .

SELECT manufacture.name, product.nameFROM manufacturer, productWHERE manufacturer.id = product.manufacturer_id

Page 12: RDBMS MySQL. MySQL is a Relational Database Management System MySQL allows multiple tables to be related to each other. Similar to a Grandparent to a

The SQL call to retrieve this data is called a JOIN

• Additional parts of the WHERE statement can be added as well as ORDER Bys and GROUP BYs