Database Design and Creation Using MySQL

Database Design
and Creation Using MySQL
Track 3 : Basic Course in Database
Learning Objectives:
At the end of the session, you should be able to:
 Model a database
 Understand (Relational Database Management System)
RDBMS concept
 Appreciate MySQL as an open-source RDBMS
Database Design
Entity-Relationship Diagram (ERD) is a tool
for modeling data.
3 concepts to remember about ERD
– Entity - the main object in the problem domain.
– Attribute - describes the main object (entity).
– Relation - association defines the between entity.
Database Case Study
Wilma:
Mayang:
I suggest you use a
DBMS to help you
manage your data...
I have a problem in my
Resource Center
How to maintain an
inventory of contact
individuals and
institutions?
Steps to Create ERD
• Identify the entity
• Identify the entity's attributes
• Identify the relation between entities
Steps to Create ERD
• Identify the entity
PERSON
INSTITUTION
Steps to Create ERD
• Identify the entity's attributes
1st Form
PERSON
Name
Home address
Home phone no
Home fax no
Email address
Age
Specialization
Office name
Position held
Office address
Office phone
Office fax number
INSTITUTION
Name
Address
Phone number
Fax number
Type of
organization
Area of service
Contact person
e-mail address
Steps to Create ERD
• Identify the entity's attributes
2nd Form
PERSON
*PersonID
Title
FirstName
MiddleInitial
LastName
HomeAddress1
HomeAddress2
HomeCountry
HomePhoneNo
HomeFaxNo
EmailAddress
Birthday
MajorSpecialization
OtherSpecialization
PositionHeld
INSTITUTION
*InstitutionID
Name
Address1
Address2
Country
PhoneNumber
FaxNumber
TypeOfOrganization
AreaOfService
ContactPerson
EmailAddress
Steps to Create ERD
• Identify the relation between entities
PERSON
*PersonID
Title
FirstName
MiddleInitial
LastName
HomeAddress1
HomeAddress2
HomeCountry
HomePhoneNo
HomeFaxNo
EmailAddress
Birthday
MajorSpecialization
OtherSpecialization
InstitutionID
PositionHeld
INSTITUTION
*InstitutionID
Name
Address1
Address2
Country
belongs to PhoneNumber
FaxNumber
TypeOfOrganization
has
AreaOfService
ContactPerson
EmailAddress
Database: Contacts
Table Name: PERSON
Column Name
*PersonID
Data Type
Table Name: INSTITUTION
Column Name
Data Type
*InstitutionID
Title
Name
FirstName
Address1
MiddleInitial
Address2
LastName
Country
HomeAddress1
PhoneNumber
HomeAddress2
FaxNumber
HomeCountry
TypeOfOrganization
HomePhoneNo
AreaOfService
HomeFaxNo
ContactPerson
EmailAddress
EmailAddress
Birthday
MajorSpecialization
OtherSpecialization
InstitutionID
PositionHeld
Additional DBMS Concepts
• Relational DBMS (RDBMS
– Commercial RDBMS (expensive)
• Oracle, Informix, SQL Server
– GNU General Public License software (free)
• MySQL, mSQL or PostGres.
MySQL
• A Relational Database Management System
(RDBMS) that is multi-user
• Say it as ``My Ess Que Ell".
several computer
workstations can
access and write into
a single database
Where to get MySQL
• Stable version at this time is MySQL version
3.22.x.
• Asia:
 China [Freecode] http://mysql.freecode.com.cn
 China [Netfirm] http://mysql.netfirm.net
 Korea [KREONet] http://linux.kreonet.re.kr/mysql/
 Japan [Soft Agency] http://www.softagency.co.jp/MySQL
Where to get MySQL
• Stable version at this time is MySQL version
3.22.x.
• Asia:
 Japan [Nagoya Syouka University]
http://mirror.nucba.ac.jp/mirror/mysql or
ftp://mirror.nucba.ac.jp/mirror/mysql
 Singapore [HJC] http://mysql.hjc.edu.sg or
ftp://ftp.hjc.edu.sg/mysql
 Taiwan [HT] http://mysql.ht.net.tw
Where to get MySQL
• Stable version at this time is MySQL version
3.22.x.
• Australia:
 Australia [AARNet/Queensland]
http://mirror.aarnet.edu.au/mysql or
ftp://mirror.aarnet.edu.au/pub/mysql
 Australia [Blue Planet/Melbourne]
http://mysql.bluep.com/
 Australia [ITworks Consulting/Victoria]
http://mysql.itworks.com.au
MySQL Datatypes
• INT
– can contain values up to 2147483648
• INT
• INT(3)
• REAL
– can contain values from-3.402823466E+38 to 1.175494351E-38, 0 and 1.175494351E-38 to
3.402823466E+38
MySQL Datatypes
• DECIMAL[(M[,D])]
• DECIMAL(5,2)
• CHAR(length)
– fixed character length, wastes diskspace
• CHAR(10)
• VARCHAR(length)
– variable character length, economical to use
• VARCHAR(10)
MySQL Datatypes
• DATE
– Y2K Compliant
– displays DATE values in 'YYYY-MM-DD'
format
• TIME
– displays TIME values in 'HH:MM:SS' format
• DATETIME
– displays DATETIME values in 'YYYY-MM-DD
HH:MM:SS' format
Recommended MySQL datatypes
•
•
•
•
INT
DECIMAL (M,D)
VARCHAR(length)
DATE
DATA DICTIONARY
Database: Contacts
Table Name: PERSON
Column Name
*PersonID
Data Type
INT
Table Name: INSTITUTION
Column Name
Data Type
*InstitutionID
INT
Title
VARCHAR(5)
Name
VARCHAR(200)
FirstName
VARCHAR(50)
Address1
VARCHAR(100)
MiddleInitial
VARCHAR(3)
Address2
VARCHAR(100)
LastName
VARCHAR(50)
Country
VARCHAR(100)
HomeAddress1
VARCHAR(100)
PhoneNumber
VARCHAR(100)
HomeAddress2
VARCHAR(100)
FaxNumber
VARCHAR(100)
HomeCountry
VARCHAR(50)
TypeOfOrganization
VARCHAR(30)
HomePhoneNo
VARCHAR(100)
AreaOfService
VARCHAR(50)
HomeFaxNo
VARCHAR(100)
ContactPerson
VARCHAR(100)
EmailAddress
VARCHAR(100)
EmailAddress
VARCHAR(100)
Birthday
DATE
MajorSpecialization
VARCHAR(50)
OtherSpecialization
VARCHAR(100)
InstitutionID
INT
PositionHeld
VARCHAR(100)