This document contains contact information for Mr. Warawut Khangkhan and summaries of chapters from his book on MySQL. It includes his Facebook, Twitter, email and mobile contact details. It then summarizes key MySQL commands like selecting a database, data types like numeric, date/time and string types, and SQL statements for creating databases and tables, altering tables, and performing operations like INSERT, DELETE, and UPDATE.
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
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
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
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
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