Вы находитесь на странице: 1из 16

Introduction to MySQL

NELINET October 28th, 2005

Preliminary Definitions
MySQL: An Open Source, Enterprise-level, multi-threaded, relational database management system that stores and retrieves data using the Structured Query Language

Structured Query Language (SQL): A standardized query language for getting information from a relational database. Relational Database: A database that stores data in the form of relational tables as 0pposed to flat files. Database Management System (DBMS): A system that manages relational databases; A collection of programs that enabling the storage, modification, and extraction of information from a database.

Cells, Rows, Tables and Databases


Cell -- a single (scalar) value.

12134

Cells, Rows, Tables and Databases


Row -- a group of scalar values representing a single instance of an object or event.

12135

1310391314 Letter: July 23,1842

Cells, Rows, Tables and Databases


Table -- a series of rows describing separate objects or events.

ID
1 21 34 1 21 35 1 21 36

METSID

LABEL

1 09031 331 3 Letter: Nov ember 1 8, 1 838 1 31 0391 31 4 Letter: July 23,1 842 1 31 302041 4 Waterloo at Sunset

Cells, Rows, Tables and Databases


Database -- a collection of related tables describing various facets of a group of objects or events.

OBJECTS ID METSID LABEL

CLINKS METSID COLID

COLS ID NAME URL ABSTRACT

Relations -- One to One


Table1 Record Record Record Record Record Record Record Table2 Record Record Record Record Record Record Record

Relations -- One to Many


Table1 Record Record Record Record Record Record Record Table2 Record Record Record Record Record Record Record

Relations -- Many to Many


Table1 Record Record Record Record Record Record Record Table2 Record Record Record Record Record Record Record

Database Design
Sketch out your data and how the different pieces of data should be grouped and how they relate to one another. In fact, you can save yourself a great deal of frustration down the road if you take the time to think things through before you get started actually building the database.
Literally draw it out in a diagram before you start!

Database Design - 1st Normal Form


Each table should have a column that identifies a row (primary key). No two rows can be identical. Groups of cells should never repeat. Each column must have a unique name. Each column must contain scalar values.

Database Design - 2nd Normal Form


Each cell in a row must depend on the primary key.

Database Design - 3rd Normal Form


No cell that is dependent on the primary key can be used to control another nonprimary key cell.

A Bad Data Model...


INVOICE 65 65 65 65 66 66 LINE 1 2 3 4 1 1 VENDOR COMPANY A COMPANY A COMPANY A COMPANY A COMPANY B COMPANY B PRODUCT WIDGET 1 WIDGET 2 WIDGET 3 WIDGET 4 WIDGET 1 WIDGET 3 QTY 1 3 2 3 1 2 COST $10.00 $20.00 $34.00 $17.00 $10.00 $34.00 DATE 2/12/02 2/12/02 2/12/02 2/12/02 4/11/02 4/11/02

Do we have a primary key? Do we have normality problems?

A Better Data Model...

INVOICE VENDOR 65 COMPANY A 66 COMPANY B

DATE 2/12/02 4/11/02

LINEID 121 122 123 124 125 126

INVOICE 65 65 65 65 66 66

LINE 1 2 3 4 1 1

PRODUCT QTY WIDGET 1 1 WIDGET 2 3 WIDGET 3 2 WIDGET 4 3 WIDGET 1 1 WIDGET 3 2

COST $10.00 $20.00 $34.00 $17.00 $10.00 $34.00

Work Break!!
Lets think about pizza...

Вам также может понравиться