MySQL

1,041 views
951 views

Published on

MySQL

Published in: Education, Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,041
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
35
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

MySQL

  1. 1. Mr.Warawut KhangkhanFacebook:Facebook: http://www.facebook.com/AjWarawut Twitter: http://twitter.com/awarawut E-Mail: awarawut@hotmail.com Mobile: 089-461-9591 089-461-
  2. 2. Mr.Warawut Khangkhan Chapter 6 MySQL 2
  3. 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 exitMr.Warawut Khangkhan Chapter 6 MySQL 3
  4. 4. Mr.Warawut Khangkhan Chapter 6 MySQL 4
  5. 5. Data type Numeric Date and Time StringMr.Warawut Khangkhan Chapter 6 MySQL 5
  6. 6. Numeric Data type Byte Signed UnsignedTINYINT[(M)] 1 -128 127 0 255SMALLINT[(M)] 2 -32768 32767 0 65535MEDIUMINT[(M)] 3 -8388608 0 16777215 8388607INT[(M)], 4 -2147483648 0 4294967295INTEER[(M)] 2147483647 -9223372036854775808 0BIGINT[(M)] 8 18446744073709551615 9223372036854775807Mr.Warawut Khangkhan Chapter 6 MySQL 6
  7. 7. Numeric Data type Byte Signed UnsignedFLOAT[(M)] 4 -3.402823466E+38 1.175494351E-38 -1.175494351E-38 3.402823466E+38 -1.7976931348623157E+308 2.2250738585072014E-308DOUBLE[(M, D)], 8DOUBLE, -2.2250738585072014E-308 1.7976931348623157E+308PRECISION[(M, D)],REAL[(M, D)]DECIMAL[(M[,D])], M+2 F (M)DEC[(M[,D])], charNUMERIC[(M[,D])]Mr.Warawut Khangkhan Chapter 6 MySQL 7
  8. 8. Date and Time Data type Format RangeDATE YYYY-MM-DD 1000-01-01 9999- 12-31DATETIME YYYY-MM-DD 1000-01-01 00:00:00 HH:MM:SS 9999-12-31 23:59:59TIMESTAMP[(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. 9. Date and Time Data type Format RangeTIME HH:MM:SS -838:59:59 838:59:59YEAR[(2|4)] YYYY F 2 F F . . F F F 1970 2069 F 4 F F . . F F F 1901 2155Mr.Warawut Khangkhan Chapter 6 MySQL 9
  10. 10. String F F CHAR VARCHAR F F (Binary) F F F TEXT BLOB F F ( F F F F ) – ENUM SETMr.Warawut Khangkhan Chapter 6 MySQL 10
  11. 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 LONGTEXTMr.Warawut Khangkhan Chapter 6 MySQL 11
  12. 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 FMr.Warawut Khangkhan Chapter 6 MySQL 12
  13. 13. Mr.Warawut Khangkhan Chapter 6 MySQL 13
  14. 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 64Mr.Warawut Khangkhan Chapter 6 MySQL 14
  15. 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. 16. create_definition F 3 F F ( F) F 64 F F FMr.Warawut Khangkhan Chapter 6 MySQL 16
  17. 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. 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. 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. 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. 21. Alter Table format: ALTER [IGNORE] TABLE tbl_name alter_specification [, alter_specification …] alter_specification F F ADD, ALTER, CHANGE, MODIFY, DROP, RENAMEMr.Warawut Khangkhan Chapter 6 MySQL 21
  22. 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. 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. 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. 25. alter_specification F F( 1) CHANGE [COLUMN] col_name create_defintionalter table table_a change field2 field2_new tinyint(1); F F( 2) MODIFY create_defintionMr.Warawut Khangkhan Chapter 6 MySQL 25
  26. 26. alter_specification F DROP [COLUMN] col_name primary key DROP PRIMARY KEY F DROP INDEX index_nameMr.Warawut Khangkhan Chapter 6 MySQL 26
  27. 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. 28. Mr.Warawut Khangkhan Chapter 6 MySQL 28
  29. 29. Data Operator F ( INSERT INTO) INSERT INTO tbl_name (col1, col2 ) VALUES (val1, val2) RENAME TABLE tbl_name SET col_name = expressionMr.Warawut Khangkhan Chapter 6 MySQL 29
  30. 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_nameMr.Warawut Khangkhan Chapter 6 MySQL 30
  31. 31. Mr.Warawut Khangkhan Chapter 6 MySQL 31
  32. 32. Books . Insight PHP F . : , 2550. 568 F. . F PHP. ( F 4). : F F F, 2547.Mr.Warawut Khangkhan Chapter 6 MySQL 32

×