chapter 4 introduction to mysql. mysql “the world’s most popular open-source database...

11
Chapter 4 Introduction to MySQL

Upload: grant-james

Post on 01-Jan-2016

232 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”

Chapter 4

Introduction to MySQL

Page 2: Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”

MySQL

• “the world’s most popular open-source database application”

• “commonly used with PHP”

Page 3: Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”

Relational Database

• On csweb.hh.nku.edu, you have a database db_fall15_username (ex. db_fall15_frank)

• Collection of tables– look like Excel spreadsheets

Page 4: Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”

4

• Each table represents a class of objects = a set of objects of the same type / kind– E.g. customers, orders– Table Customers in the db for Book-O-Rama store (running example):

• A table has:– A name – Customers– Structure = a number of columns – customerid, name, address, city– Rows – currently, data about 3 customers in this table

Relational DB Concepts: Tables

Page 5: Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”

bookorama.sql

• Tables– customers– orders– books– order_items– book_reviews

Page 6: Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”

MySQL Data Types

• CHAR(50) – fixed length character field• TEXT – string with maximum length 65,535

characters• INT – integer• TINYINT – 1 byte integer (signed -128..127,

unsigned 0..255)

Page 7: Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”

MySQL Data Types

• FLOAT(6,2) - floating point – 6 digits, 2 decimal places

• DATE – YYYY-MM-DD• TIMESTAMP – YYYYMMDDHHMMSS (when

UPDATE or INSERT is performed)• DOUBLE(10,2) – larger floating point – 10

digits, 2 decimal places

Page 8: Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”

MySQL Data Types

• DECIMAL(7,2) – for accurate dollars and cents calculations

• ENUM(‘M’,’F’) – enumeration of values

Page 9: Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”

COLUMN PROPERTIES

• UNSIGNED- positive numbers and zero• NOT NULL

– NULL = no value– Must have a value

• PRIMARY KEY– Unique– Social Security Number– ISBN

Page 10: Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”

COLUMN PROPERTIES

• AUTOINCREMENT PRIMARY KEY– 1, 2, 3, 4, … - assign each record an id

Page 11: Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”

MySQL Client

mysql.exemysql –h csweb.hh.nku.edu – u username –p