Ch4
Ch4
1
Introduction
• The MySQL software comes with the database server (which stores
the actual data), different client applications (for interacting with the
database server), and several utilities.
2
Naming Data
Base element
• With that in mind, the examples in this chapter and the next
will use a database that stores some user registration
information.
3
Cont.
When creating databases and tables, you should come up with names
(formally called identifiers) that are clear, meaningful, and easy to type. Also,
identifiers:
◆ Should only contain letters, numbers, and the underscore (no spaces)
4
name a database’s elements:
Column Name
User_ID
First_Name
Last_Name
Pass
5
hoosing your column types
Once you have identified all of the tables and columns that the database
will need, you should determine each column’s data
type. When creating a table, MySQL requires that you explicitly state what
sort of information each column will contain. There are three primary
types, which is true for almost every database application:
◆ Numbers
6
Other MySQL Data types
TIME.
7
o select the column types:
User_ID Number
First_Name Text
Last_Name Text
Email Text
Pass Text
RegDate Date/time
8
Cont.
User_ID MEDIUMINT
First_Name VARCHAR(15)
Last_Name VARCHAR(40)
Email VARCHAR(40)
Pass CHAR(40)
RegDate Date/time
9
Char Vs. Varchar
10
Cont.
11
Tips
value
12
oosing other column properties
every table should have a value, but that isn’t always the case.
• To force a field to have a value, add the NOT NULL description to its
13
Cont.
• When creating a table, you can also specify a default value for any
• a default will save you from having to specify a value when inserting
14
Cont.
15
Cont.
16
finish defining your columns:
17
exes, Keys, and AUTO_INCREMENT
• Two concepts closely related to database design are indexes and keys. An
index in a database is a way of requesting that the database keep an eye
on the values of a specific column or combination of columns (loosely
stated).
• Each table should have one primary key, and the primary key in one
table is often linked as a foreign key in another.
18
Any Questions?
19