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

INTRODUCTION TO

MYSQL

HAROLD R. LUCERO,MIT

MYSQL

DEFINITION OF TERMS

Relational Database: in relational databases such as


MySQL, data is stored in tables made up of one or more
fields. (MySQL calls a column a field). The data stored in
each column must be of a single data type int,varchar or
date.
DATABASE MANAGEMENT SYSTEM

MYSQL

DEFINITION OF TERMS

Table: Tables are the main units of data storage in a


database. A table is a collection of data about a specific
topic; it is made up of one of more fields.
DATABASE MANAGEMENT SYSTEM

MYSQL

DEFINITION OF TERMS

Record: A collection of values from each column of a table is


called a record or a row in the table.
DATABASE MANAGEMENT SYSTEM

MYSQL

DEFINITION OF TERMS

Field: a field is a column in a table and defines a data type


for a set of values in a table. For example, a mailing list table
might include fields for first name, last name, address, city,
state, zip code, and telephone number.
DATABASE MANAGEMENT SYSTEM

MYSQL

DEFINITION OF TERMS
Data Type: data types are the
properties of each field. A field
only has one data type, such as
Character, Number or Date.

Primary Key: a primary


key is a value that can
be used to identify a
unique record in a
table.
DATABASE MANAGEMENT SYSTEM

MYSQL

DATABASE COMPONENTS
Table: Tables are where the actual data is defined and
entered.
Queries: Queries are basically questions about the data in a
database. Queries allow you to extract data based on the
criteria you define.
Forms: Forms are designed to ease the data entry process.
For example, you can create a data entry form that looks
exactly like a paper form .
Reports: when you want to print records from your
database, design a report.
DATABASE MANAGEMENT SYSTEM

MYSQL

STEPS IN PLANNING A DATABASE


1. Determine the purpose of your database
2. Determine the tables you need in the database
3. Determine the fields that you need
4. Identify fields with unique values for each records
5. Determine the relationship between tables
6. Filter your design
7. Re-examine what fields will go into your database
8. Create the database and its objects and enter data
DATABASE MANAGEMENT SYSTEM

MYSQL

NAMING CONVENTIONS
Avoid Quotes
Lowercase
Data types are not names
Underscores separate words
Full words, not abbreviations
Use common abbreviations
Avoid reserved words

DATABASE MANAGEMENT SYSTEM

MYSQL

SINGULAR RELATIONS
Tables, views, and other relations that hold data
should have singular names, not plural. This means
our tables and views would be named team, not teams.

DATABASE MANAGEMENT SYSTEM

MYSQL

PREFIXES AND SUFFIXES


Some (older) guidelines suggest naming tables with a
TB_ prefix, views with a VW_ prefix, or stored
procedures with a SP_ prefix.

DATABASE MANAGEMENT SYSTEM

MYSQL

DATATYPES IN MYSQL
Numeric Data Types

DATABASE MANAGEMENT SYSTEM

MYSQL

DATATYPES IN MYSQL
Numeric Data Types

DATABASE MANAGEMENT SYSTEM

MYSQL

DATATYPES IN MYSQL
String Data Types
CHAR(M) - A fixed-length string between 1 and
255 characters in length (for example CHAR(5)),
right-padded with spaces to the specified length
when stored. Defining a length is not required, but
the default is 1.
VARCHAR(M) - A variable-length string between 1
and 255 characters in length; for example
VARCHAR(25). You must define a length when
creating a VARCHAR field.
DATABASE MANAGEMENT SYSTEM

MYSQL

DATATYPES IN MYSQL
String Data Types
BLOB or TEXT - A field with a maximum length of
65535 characters. BLOBs are "Binary Large
Objects" and are used to store large amounts of
binary data, such as images or other types of files.
Fields defined as TEXT also hold large amounts of
data; the difference between the two is that sorts
and comparisons on stored data are case sensitive
on BLOBs and are not case sensitive in TEXT fields.
You do not specify a length with BLOB or TEXT.
DATABASE MANAGEMENT SYSTEM

MYSQL

DATATYPES IN MYSQL
String Data Types
TINYBLOB or TINYTEXT - A BLOB or TEXT
column with a maximum length of 255 characters.
You do not specify a length with TINYBLOB or
TINYTEXT.
MEDIUMBLOB or MEDIUMTEXT - A BLOB or
TEXT column with a maximum length of 16777215
characters. You do not specify a length with
MEDIUMBLOB or MEDIUMTEXT.

DATABASE MANAGEMENT SYSTEM

MYSQL

DATATYPES IN MYSQL
String Data Types
LONGBLOB or LONGTEXT - A BLOB or TEXT
column with a maximum length of 4294967295
characters. You do not specify a length with
LONGBLOB or LONGTEXT
ENUM - An enumeration, which is a fancy term for
list. When defining an ENUM, you are creating a list
of items from which the value must be selected (or it
can be NULL).

DATABASE MANAGEMENT SYSTEM

MYSQL

DATATYPES IN MYSQL
Date and Time Data Types

DATABASE MANAGEMENT SYSTEM

MYSQL

FIELD PROPERTIES
LEN Specifies the length
DEFAULT This property allows you to set the default
value for the field.
PRIMARY KEY - The PRIMARY KEY constraint uniquely
identifies each record in a database table.
NOT NULL - The NOT NULL constraint enforces a
column to NOT accept NULL values.

DATABASE MANAGEMENT SYSTEM

MYSQL

FIELD PROPERTIES
UNSIGNED - Make any numeric type UNSIGNED if it
won't ever store negative numbers
ZEROFILL - the field numeric values will be positive or 0
and leading zeros will be added to a number
AUTO_INCREMENT - description is also added to the
column, which tells MySQL to use the next-highest
number as the user_id value for each added record

DATABASE MANAGEMENT SYSTEM

MYSQL

MANAGING A DATABASE
Login in MySQL Database

DATABASE MANAGEMENT SYSTEM

MYSQL

MANAGING A DATABASE
Creating a Database
Before doing anything else with the data, you need to
create a database. A database is a container of data. It
stores contacts, vendors, customers or any kind of data
that you can think of. In MySQL, a database is a
collection of objects that are used to store and
manipulate data such as tables, database views,
triggers, stored procedures, etc.

DATABASE MANAGEMENT SYSTEM

MYSQL

MANAGING A DATABASE
Displaying Databases
The SHOW DATABASES statement displays all
databases in the MySQL database server. You can use
the SHOW DATABASES statement to check the database
that youve created or to see all the databases on the
database server before you create a new database, for
example:

DATABASE MANAGEMENT SYSTEM

MYSQL

MANAGING A DATABASE
Selecting a database to work with
Before working with a particular database, you
must tell MySQL which database you want to work with by
using the USE statement.

DATABASE MANAGEMENT SYSTEM

MYSQL

MANAGING A DATABASE
Removing Databases
Removing database means you delete the
database physically. All the data and associated objects
inside the database are permanently deleted and this
cannot be undone. Therefore, it is very important to
execute this query with extra cautions.

DATABASE MANAGEMENT SYSTEM

MYSQL

HOW TO CREATE A TABLE


1. Specify the fields for the table
2. Determine the data type for each field
3. Determine the field properties of each fields
4. Assign the Primary Key
5. Save and name the Table

DATABASE MANAGEMENT SYSTEM

MYSQL

MANAGING A DATABASE
Creating Tables
In order to create a new table within a database,
you use the MySQL CREATE TABLE statement. The
CREATE TABLE statement is one of the most complex
statement in MySQL

DATABASE MANAGEMENT SYSTEM

MYSQL

MANAGING A DATABASE
Creating Tables
To define a column for the table in the CREATE
TABLE statement, you use the following syntax:

DATABASE MANAGEMENT SYSTEM

MYSQL

MANAGING A DATABASE
Creating Tables
Ex.

DATABASE MANAGEMENT SYSTEM

MYSQL

ACTIVITY 1
1. Create a database in localhost and use your LastName as your database
name
2. Set your database as the active database and create the table below using
member as the table name.

FIELDS
memberid
first_name
middle_name
last-named
birthday

DATABASE MANAGEMENT SYSTEM

DATATYPE

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