/*进阶12SQL 数据类型介绍数值型: 整数: Tinyint(1b) < mediumint(3b)2038年 */
#1 溢出保护DROP TABLE IF EXISTS tab_int;CREATE TABLE tab_int( t1 INT, t2 INT UNSIGNED);INSERT INTO tab_int VALUES(100000000000000,-100); #2147483647,0DESC tab_int;SELECT * FROM tab_int; #2 设置位数,0填充宽度CREATE TABLE tab2_int( t1 INT(7) ZEROFILL, t2 INT(7) UNSIGNED ZEROFILL);INSERT INTO tab2_int VALUES(123,123); # 0000123 , 0000123DESC tab2_int;SELECT * FROM tab2_int; #3 测试溢出CREATE TABLE tab_float( f1 FLOAT(5,2), f2 DOUBLE(5,2), f3 DECIMAL(5,2));SELECT * FROM tab_float;INSERT INTO tab_float VALUE(123.456,123.4444,123.55); #123.46,123.44,123.55INSERT INTO tab_float VALUE(123.456,123.4444,123456.55); #123.46,123.44,999.99 #4 测试enum 枚举型CREATE TABLE tab_char( row1 ENUM('a','b','c','d'));INSERT INTO tab_char VALUES('a'); #aINSERT INTO tab_char VALUES('M'); #' 'INSERT INTO tab_char VALUES('A'); #'a'SELECT * FROM tab_char; #5 测试set 集合类型DROP TABLE IF EXISTS tab_set;CREATE TABLE tab_set( row1 SET('a','b','c','d'));INSERT INTO tab_set VALUES('a,c,d'); #aSELECT * FROM tab_set; #四:日期型 CREATE TABLE tab_date( t1 DATETIME, t2 TIMESTAMP);INSERT INTO tab_date VALUES(NOW(),NOW()); #2018-10-29 15:13:24,2018-10-29 15:13:24SELECT * FROM tab_date;SHOW VARIABLES LIKE 'time_zone';SET time_zone='+9:00'; # 2018-10-29 15:13:24 ,2018-10-29 16:13:24