SlideShare uma empresa Scribd logo
1 de 32
Baixar para ler 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

Mais conteúdo relacionado

Mais de 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
 

Mais de 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
 

Último

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIShubhangi Sonawane
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
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.pdfPoh-Sun Goh
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
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
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
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.pptxAreebaZafar22
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
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
 

Último (20)

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
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
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
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
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
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
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
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 ...
 

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