SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Mehr von Warawut

Object-Oriented Programming 1
Object-Oriented Programming 1Object-Oriented Programming 1
Object-Oriented Programming 1
Warawut
 

Mehr von 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
 

Kürzlich hochgeladen

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Kürzlich hochgeladen (20)

HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 

MySQL

  • 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