910 likes | 2.38k Views
RDBMS. MySQL. 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. Table Fields.
E N D
RDBMS MySQL
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.
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.
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.
Basic Flat table A flat table with manufacturer, product and comments. Basic until you start adding more data
Basic Flat table More data Issues with duplicate info Table data sizes increases
Basic Flat table Data may not be the same or inconsistent
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.
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.
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.
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.name FROM manufacturer, product WHERE manufacturer.id = product.manufacturer_id
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