SlideShare a Scribd company logo
1 of 32
Download to read offline
Mr.Warawut Khangkhan
Facebook:
Facebook: http://www.facebook.com/AjWarawut
           Twitter: http://twitter.com/awarawut
                E-Mail: awarawut@hotmail.com
                            Mobile: 089-461-9591
                                     089-461-
Mr.Warawut Khangkhan   Chapter 6 MySQL   2
MySQL Command Prompt
    XAMPP
       c:xamppmysqlbin
       c:xamppmysql
                         F        mysql
              --help
       mysql --help
               F   Database Server
       mysql –h host –u user -p
    or
       mysql -u user -p
                 F  Database Server
       quit or exit
Mr.Warawut Khangkhan   Chapter 6 MySQL    3
Mr.Warawut Khangkhan   Chapter 6 MySQL   4
Data type
    Numeric
    Date and Time
    String




Mr.Warawut Khangkhan   Chapter 6 MySQL   5
Numeric
       Data type                Byte         Signed     Unsigned
TINYINT[(M)]                       1     -128 127     0 255
SMALLINT[(M)]                      2     -32768 32767 0 65535
MEDIUMINT[(M)]                     3     -8388608               0    16777215
                                         8388607
INT[(M)],                          4     -2147483648            0    4294967295
INTEER[(M)]                              2147483647
                                         -9223372036854775808   0
BIGINT[(M)]                        8                            18446744073709551615
                                         9223372036854775807



Mr.Warawut Khangkhan   Chapter 6 MySQL                                                 6
Numeric
       Data type                Byte               Signed     Unsigned
FLOAT[(M)]                         4     -3.402823466E+38 1.175494351E-38

                                         -1.175494351E-38           3.402823466E+38
                                         -1.7976931348623157E+308   2.2250738585072014E-308
DOUBLE[(M, D)],                    8
DOUBLE,                                  -2.2250738585072014E-308   1.7976931348623157E+308
PRECISION[(M, D)],
REAL[(M, D)]
DECIMAL[(M[,D])],               M+2            F                       (M)
DEC[(M[,D])],                                         char
NUMERIC[(M[,D])]
Mr.Warawut Khangkhan   Chapter 6 MySQL                                                        7
Date and Time
    Data type                 Format                       Range
DATE                       YYYY-MM-DD             1000-01-01 9999-
                                                  12-31
DATETIME                   YYYY-MM-DD             1000-01-01 00:00:00
                           HH:MM:SS                  9999-12-31
                                                  23:59:59
TIMESTAMP[(M)] YYYYMMDDHHMM 1970-01-01 00:00:00
                           SS,                         . . 2037
                           YYMMDDHHMMSS,
                           YYYYMMDD
                           YYMMDD           F F M
 Mr.Warawut Khangkhan
                               F F 14, 12, 8
                      Chapter 6 MySQL
                                                6                    8
Date and Time
    Data type                            Format            Range
TIME                     HH:MM:SS                 -838:59:59
                                                  838:59:59
YEAR[(2|4)]              YYYY                          F      2       F
                                                   F . .       F F            F
                                                  1970 2069
                                                         F    4           F
                                                    F . .       F F           F
                                                  1901 2155



Mr.Warawut Khangkhan   Chapter 6 MySQL                                            9
String
       F                         F          CHAR     VARCHAR
       F                   F              (Binary) F F            F
           TEXT            BLOB
      F                               F                     ( F
                       F                     F   F   ) – ENUM   SET




Mr.Warawut Khangkhan       Chapter 6 MySQL                            10
String
                Data type                           Range
 CHAR(M)                                 1   255
 VARCHAR(M)                              1   255
 TINYBLOB TINYTEXT                       1   255
 BLOB TEXT                               1   65535
 MEDIUMBLOG                              1   16777215
 MEDIUMTEXT
 LONGBLOB                                1   4294967295
 LONGTEXT


Mr.Warawut Khangkhan   Chapter 6 MySQL                      11
F                           F CHAR              VARCHAR
                  F               F                CHAR           F           F               F        F
                      F       F                   VARCHAR                             F
       F
               F F  F                                     CHAR        F           F       F       F
                F F                               F          CHAR F                                   F F F
           VARCHAR                            F            F              F                             F 1 byte
           F                                          F




Mr.Warawut Khangkhan                  Chapter 6 MySQL                                                              12
Mr.Warawut Khangkhan   Chapter 6 MySQL   13
Create and Drop Database
    Create Database
        CREATE DATABASE [IF NOT EXISTS]
    db_name
    Drop Database
       DROP DATABASE [IF EXISTS] db_name

               db_name                       F        F   F /.
                   F                     F       64


Mr.Warawut Khangkhan   Chapter 6 MySQL                            14
Create Table
 format:
   CREATE [TEMPORARY] TABLE [IF NOT EXISTS]
    tbl_name
        [(create_definition, …)]
        [table_options]
        [select_statement]




Mr.Warawut Khangkhan   Chapter 6 MySQL        15
create_definition
               F 3 F
                 F ( F)                F    64
           F                F
      F




Mr.Warawut Khangkhan      Chapter 6 MySQL        16
F                                      create_definition
 [NOT NULL | NULL]
 [DEFAULT default_value]
 [AUTO_INCREMENT]
 [PRIMARY KEY] [reference_definition]
   or PRIMARY KEY (index_col_name, …)
   or KEY [index_name] (index_col_name, …)
   or INDEX [index_name] (index_col_name, …)
   or UNIQUE [INDEX] [index_name] (index_col_name, …)
   or FULLTEXT [INDEX] [index_name] (index_col_name, …)
   or [CONSTRAINT symbol] FOREIGN KEY [index_name]
        (index_col_name, …) [reference_definition]
   or CHECK (expr)


Mr.Warawut Khangkhan   Chapter 6 MySQL                       17
F           1: create table
 create table if not exists saleorder
   (OrderNo varchar(15) primary key,
   CustomerNo varchar(20),
   OrderDate datetime,
   PromiseDate date,
   Note varchar(80));




Mr.Warawut Khangkhan    Chapter 6 MySQL   18
F           2: create table
 create table saleorder_detail
   (OrderNo varchar(15) not null,
   SequenceNo int(3) not null,
   ItemNo varchar(20),
   Qty double(10, 2),
   primary key (OrderNo, SequenceNo));




Mr.Warawut Khangkhan    Chapter 6 MySQL   19
F           3: create table
 create table saleorder_detail
   (ID int auto_increment primary key,
   OrderNo varchar(15) not null,
   SequenceNo int(3) not null,
   ItemNo varchar(20),
   Qty double(10, 2),
   UnitPrice double(14, 4),
   Amount double(14, 4),
   OrderStatus char(1) default ‘A’);


Mr.Warawut Khangkhan    Chapter 6 MySQL   20
Alter Table
 format:
   ALTER [IGNORE] TABLE tbl_name
      alter_specification [, alter_specification …]

       alter_specification F F  ADD, ALTER,
           CHANGE, MODIFY, DROP, RENAME




Mr.Warawut Khangkhan   Chapter 6 MySQL                21
alter_specification
            F
    ADD [COLUMN] create_definition [FIRST |
    AFTER column_name]

 alter table table_a add field0 varchar(10) first;
 alter table table_a add field5 int after field4;

            F
    ADD INDEX [index_name] (col_name, …)
 alter table table_a add index (field0);

Mr.Warawut Khangkhan   Chapter 6 MySQL               22
alter_specification
       F primary key
    ADD PRIMARY KEY (col_name, …)

 alter table table_a add primary key (field0, field1);

       F unique index
    ADD UNIQUE [index_name] (col_name, …)




Mr.Warawut Khangkhan   Chapter 6 MySQL                   23
alter_specification
                   F  F     F
    ALTER [COLUMN] col_name {SET DEFAULT
    literal | DROP DEFAULT}

 alter table table_a alter field2 set default ‘noname’;
 alter table table_a alter field2 drop default;




Mr.Warawut Khangkhan   Chapter 6 MySQL                24
alter_specification
       F    F(  1)
    CHANGE [COLUMN] col_name
    create_defintion

alter table table_a change field2 field2_new tinyint(1);

       F    F(    2)
    MODIFY create_defintion


Mr.Warawut Khangkhan   Chapter 6 MySQL                 25
alter_specification
           F
    DROP [COLUMN] col_name
       primary key
    DROP PRIMARY KEY
             F
    DROP INDEX index_name




Mr.Warawut Khangkhan   Chapter 6 MySQL   26
alter_specification
    RENAME TABLE tbl_name TO new_tbl_name [,
    tbl_name2 TO new_tbl_name, …]

    DROP TABLE [IF EXISTS] tbl_name [,
    tbl_name , …]




Mr.Warawut Khangkhan   Chapter 6 MySQL         27
Mr.Warawut Khangkhan   Chapter 6 MySQL   28
Data Operator
          F   (  INSERT INTO)
    INSERT INTO tbl_name (col1, col2 ) VALUES
    (val1, val2)




    RENAME TABLE tbl_name SET col_name =
    expression



Mr.Warawut Khangkhan   Chapter 6 MySQL          29
Data Operator
        F (   DELETE)
    DELETE FROM tbl_name WHERE
    where_definition
       F F   (  UPDATE)
    UPDATE tbl_name SET col_name = expression
    WHERE where_definition
           F  (  SELECT)
    SELECT select_expression FROM table_name
       WHERE where_definition
       ORDER BY col_name

Mr.Warawut Khangkhan   Chapter 6 MySQL          30
Mr.Warawut Khangkhan   Chapter 6 MySQL   31
Books
                           . Insight PHP             F
                                                     .       :       ,
    2550. 568            F.
                           .    F PHP. (   F   4).       :       F
            F          F, 2547.




Mr.Warawut Khangkhan     Chapter 6 MySQL                                 32

More Related Content

More from Warawut

Business Computer Project 4
Business Computer Project 4Business Computer Project 4
Business Computer Project 4Warawut
 
Object-Oriented Programming 10
Object-Oriented Programming 10Object-Oriented Programming 10
Object-Oriented Programming 10Warawut
 
Object-Oriented Programming 9
Object-Oriented Programming 9Object-Oriented Programming 9
Object-Oriented Programming 9Warawut
 
Object-Oriented Programming 8
Object-Oriented Programming 8Object-Oriented Programming 8
Object-Oriented Programming 8Warawut
 
Management Information System 6
Management Information System 6Management Information System 6
Management Information System 6Warawut
 
Management Information System 5
Management Information System 5Management Information System 5
Management Information System 5Warawut
 
Management Information System 4
Management Information System 4Management Information System 4
Management Information System 4Warawut
 
Object-Oriented Programming 5
Object-Oriented Programming 5Object-Oriented Programming 5
Object-Oriented Programming 5Warawut
 
Business Computer Project 3
Business Computer Project 3Business Computer Project 3
Business Computer Project 3Warawut
 
Management Information System 3
Management Information System 3Management Information System 3
Management Information System 3Warawut
 
Business Computer Project 2
Business Computer Project 2Business Computer Project 2
Business Computer Project 2Warawut
 
Chapter 2 Strategy & Information System
Chapter 2 Strategy & Information SystemChapter 2 Strategy & Information System
Chapter 2 Strategy & Information SystemWarawut
 
Object-Oriented Programming 4
Object-Oriented Programming 4Object-Oriented Programming 4
Object-Oriented Programming 4Warawut
 
Business Computer Project 1
Business Computer Project 1Business Computer Project 1
Business Computer Project 1Warawut
 
Chapter 1 Organization & MIS
Chapter 1 Organization & MISChapter 1 Organization & MIS
Chapter 1 Organization & MISWarawut
 
Object-Oriented Programming 3
Object-Oriented Programming 3Object-Oriented Programming 3
Object-Oriented Programming 3Warawut
 
Object-Oriented Programming 2
Object-Oriented Programming 2Object-Oriented Programming 2
Object-Oriented Programming 2Warawut
 
Object-Oriented Programming 1
Object-Oriented Programming 1Object-Oriented Programming 1
Object-Oriented Programming 1Warawut
 
Upload File
Upload FileUpload File
Upload FileWarawut
 

More from Warawut (20)

Business Computer Project 4
Business Computer Project 4Business Computer Project 4
Business Computer Project 4
 
Object-Oriented Programming 10
Object-Oriented Programming 10Object-Oriented Programming 10
Object-Oriented Programming 10
 
Object-Oriented Programming 9
Object-Oriented Programming 9Object-Oriented Programming 9
Object-Oriented Programming 9
 
Object-Oriented Programming 8
Object-Oriented Programming 8Object-Oriented Programming 8
Object-Oriented Programming 8
 
Management Information System 6
Management Information System 6Management Information System 6
Management Information System 6
 
Management Information System 5
Management Information System 5Management Information System 5
Management Information System 5
 
Management Information System 4
Management Information System 4Management Information System 4
Management Information System 4
 
Object-Oriented Programming 5
Object-Oriented Programming 5Object-Oriented Programming 5
Object-Oriented Programming 5
 
Business Computer Project 3
Business Computer Project 3Business Computer Project 3
Business Computer Project 3
 
Management Information System 3
Management Information System 3Management Information System 3
Management Information System 3
 
Business Computer Project 2
Business Computer Project 2Business Computer Project 2
Business Computer Project 2
 
Chapter 2 Strategy & Information System
Chapter 2 Strategy & Information SystemChapter 2 Strategy & Information System
Chapter 2 Strategy & Information System
 
Object-Oriented Programming 4
Object-Oriented Programming 4Object-Oriented Programming 4
Object-Oriented Programming 4
 
Business Computer Project 1
Business Computer Project 1Business Computer Project 1
Business Computer Project 1
 
Chapter 1 Organization & MIS
Chapter 1 Organization & MISChapter 1 Organization & MIS
Chapter 1 Organization & MIS
 
Object-Oriented Programming 3
Object-Oriented Programming 3Object-Oriented Programming 3
Object-Oriented Programming 3
 
Object-Oriented Programming 2
Object-Oriented Programming 2Object-Oriented Programming 2
Object-Oriented Programming 2
 
Object-Oriented Programming 1
Object-Oriented Programming 1Object-Oriented Programming 1
Object-Oriented Programming 1
 
Upload File
Upload FileUpload File
Upload File
 
Login
LoginLogin
Login
 

Recently uploaded

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 

Recently uploaded (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 

MySQL Database Commands for Beginners

  • 1. Mr.Warawut Khangkhan Facebook: Facebook: http://www.facebook.com/AjWarawut Twitter: http://twitter.com/awarawut E-Mail: awarawut@hotmail.com Mobile: 089-461-9591 089-461-
  • 2. Mr.Warawut Khangkhan Chapter 6 MySQL 2
  • 3. MySQL Command Prompt XAMPP c:xamppmysqlbin c:xamppmysql F mysql --help mysql --help F Database Server mysql –h host –u user -p or mysql -u user -p F Database Server quit or exit Mr.Warawut Khangkhan Chapter 6 MySQL 3
  • 4. Mr.Warawut Khangkhan Chapter 6 MySQL 4
  • 5. Data type Numeric Date and Time String Mr.Warawut Khangkhan Chapter 6 MySQL 5
  • 6. Numeric Data type Byte Signed Unsigned TINYINT[(M)] 1 -128 127 0 255 SMALLINT[(M)] 2 -32768 32767 0 65535 MEDIUMINT[(M)] 3 -8388608 0 16777215 8388607 INT[(M)], 4 -2147483648 0 4294967295 INTEER[(M)] 2147483647 -9223372036854775808 0 BIGINT[(M)] 8 18446744073709551615 9223372036854775807 Mr.Warawut Khangkhan Chapter 6 MySQL 6
  • 7. Numeric Data type Byte Signed Unsigned FLOAT[(M)] 4 -3.402823466E+38 1.175494351E-38 -1.175494351E-38 3.402823466E+38 -1.7976931348623157E+308 2.2250738585072014E-308 DOUBLE[(M, D)], 8 DOUBLE, -2.2250738585072014E-308 1.7976931348623157E+308 PRECISION[(M, D)], REAL[(M, D)] DECIMAL[(M[,D])], M+2 F (M) DEC[(M[,D])], char NUMERIC[(M[,D])] Mr.Warawut Khangkhan Chapter 6 MySQL 7
  • 8. Date and Time Data type Format Range DATE YYYY-MM-DD 1000-01-01 9999- 12-31 DATETIME YYYY-MM-DD 1000-01-01 00:00:00 HH:MM:SS 9999-12-31 23:59:59 TIMESTAMP[(M)] YYYYMMDDHHMM 1970-01-01 00:00:00 SS, . . 2037 YYMMDDHHMMSS, YYYYMMDD YYMMDD F F M Mr.Warawut Khangkhan F F 14, 12, 8 Chapter 6 MySQL 6 8
  • 9. Date and Time Data type Format Range TIME HH:MM:SS -838:59:59 838:59:59 YEAR[(2|4)] YYYY F 2 F F . . F F F 1970 2069 F 4 F F . . F F F 1901 2155 Mr.Warawut Khangkhan Chapter 6 MySQL 9
  • 10. String F F CHAR VARCHAR F F (Binary) F F F TEXT BLOB F F ( F F F F ) – ENUM SET Mr.Warawut Khangkhan Chapter 6 MySQL 10
  • 11. String Data type Range CHAR(M) 1 255 VARCHAR(M) 1 255 TINYBLOB TINYTEXT 1 255 BLOB TEXT 1 65535 MEDIUMBLOG 1 16777215 MEDIUMTEXT LONGBLOB 1 4294967295 LONGTEXT Mr.Warawut Khangkhan Chapter 6 MySQL 11
  • 12. F F CHAR VARCHAR F F CHAR F F F F F F VARCHAR F F F F F CHAR F F F F F F F CHAR F F F F VARCHAR F F F F 1 byte F F Mr.Warawut Khangkhan Chapter 6 MySQL 12
  • 13. Mr.Warawut Khangkhan Chapter 6 MySQL 13
  • 14. Create and Drop Database Create Database CREATE DATABASE [IF NOT EXISTS] db_name Drop Database DROP DATABASE [IF EXISTS] db_name db_name F F F /. F F 64 Mr.Warawut Khangkhan Chapter 6 MySQL 14
  • 15. Create Table format: CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition, …)] [table_options] [select_statement] Mr.Warawut Khangkhan Chapter 6 MySQL 15
  • 16. create_definition F 3 F F ( F) F 64 F F F Mr.Warawut Khangkhan Chapter 6 MySQL 16
  • 17. F create_definition [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT] [PRIMARY KEY] [reference_definition] or PRIMARY KEY (index_col_name, …) or KEY [index_name] (index_col_name, …) or INDEX [index_name] (index_col_name, …) or UNIQUE [INDEX] [index_name] (index_col_name, …) or FULLTEXT [INDEX] [index_name] (index_col_name, …) or [CONSTRAINT symbol] FOREIGN KEY [index_name] (index_col_name, …) [reference_definition] or CHECK (expr) Mr.Warawut Khangkhan Chapter 6 MySQL 17
  • 18. F 1: create table create table if not exists saleorder (OrderNo varchar(15) primary key, CustomerNo varchar(20), OrderDate datetime, PromiseDate date, Note varchar(80)); Mr.Warawut Khangkhan Chapter 6 MySQL 18
  • 19. F 2: create table create table saleorder_detail (OrderNo varchar(15) not null, SequenceNo int(3) not null, ItemNo varchar(20), Qty double(10, 2), primary key (OrderNo, SequenceNo)); Mr.Warawut Khangkhan Chapter 6 MySQL 19
  • 20. F 3: create table create table saleorder_detail (ID int auto_increment primary key, OrderNo varchar(15) not null, SequenceNo int(3) not null, ItemNo varchar(20), Qty double(10, 2), UnitPrice double(14, 4), Amount double(14, 4), OrderStatus char(1) default ‘A’); Mr.Warawut Khangkhan Chapter 6 MySQL 20
  • 21. Alter Table format: ALTER [IGNORE] TABLE tbl_name alter_specification [, alter_specification …] alter_specification F F ADD, ALTER, CHANGE, MODIFY, DROP, RENAME Mr.Warawut Khangkhan Chapter 6 MySQL 21
  • 22. alter_specification F ADD [COLUMN] create_definition [FIRST | AFTER column_name] alter table table_a add field0 varchar(10) first; alter table table_a add field5 int after field4; F ADD INDEX [index_name] (col_name, …) alter table table_a add index (field0); Mr.Warawut Khangkhan Chapter 6 MySQL 22
  • 23. alter_specification F primary key ADD PRIMARY KEY (col_name, …) alter table table_a add primary key (field0, field1); F unique index ADD UNIQUE [index_name] (col_name, …) Mr.Warawut Khangkhan Chapter 6 MySQL 23
  • 24. alter_specification F F F ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT} alter table table_a alter field2 set default ‘noname’; alter table table_a alter field2 drop default; Mr.Warawut Khangkhan Chapter 6 MySQL 24
  • 25. alter_specification F F( 1) CHANGE [COLUMN] col_name create_defintion alter table table_a change field2 field2_new tinyint(1); F F( 2) MODIFY create_defintion Mr.Warawut Khangkhan Chapter 6 MySQL 25
  • 26. alter_specification F DROP [COLUMN] col_name primary key DROP PRIMARY KEY F DROP INDEX index_name Mr.Warawut Khangkhan Chapter 6 MySQL 26
  • 27. alter_specification RENAME TABLE tbl_name TO new_tbl_name [, tbl_name2 TO new_tbl_name, …] DROP TABLE [IF EXISTS] tbl_name [, tbl_name , …] Mr.Warawut Khangkhan Chapter 6 MySQL 27
  • 28. Mr.Warawut Khangkhan Chapter 6 MySQL 28
  • 29. Data Operator F ( INSERT INTO) INSERT INTO tbl_name (col1, col2 ) VALUES (val1, val2) RENAME TABLE tbl_name SET col_name = expression Mr.Warawut Khangkhan Chapter 6 MySQL 29
  • 30. Data Operator F ( DELETE) DELETE FROM tbl_name WHERE where_definition F F ( UPDATE) UPDATE tbl_name SET col_name = expression WHERE where_definition F ( SELECT) SELECT select_expression FROM table_name WHERE where_definition ORDER BY col_name Mr.Warawut Khangkhan Chapter 6 MySQL 30
  • 31. Mr.Warawut Khangkhan Chapter 6 MySQL 31
  • 32. Books . Insight PHP F . : , 2550. 568 F. . F PHP. ( F 4). : F F F, 2547. Mr.Warawut Khangkhan Chapter 6 MySQL 32