1 #常见的数据类型
2
17
18 #一、整型
19
31
32 #1.如何设置无符号和有符号
33
34 DROP TABLE IF EXISTS tab_int;
35 CREATE TABLE tab_int(
36 t1 INT(7) ZEROFILL,
37 t2 INT(7) ZEROFILL
38
39 );
40
41 DESC tab_int;
42
43
44 INSERT INTO tab_int VALUES(-123456);
45 INSERT INTO tab_int VALUES(-123456,-123456);
46 INSERT INTO tab_int VALUES(2147483648,4294967296);
47
48 INSERT INTO tab_int VALUES(123,123);
49
50
51 SELECT * FROM tab_int;
52
53
54 #二、小数
55
80 #测试M和D
81
82 DROP TABLE tab_float;
83 CREATE TABLE tab_float(
84 f1 FLOAT,
85 f2 DOUBLE,
86 f3 DECIMAL
87 );
88 SELECT * FROM tab_float;
89 DESC tab_float;
90
91 INSERT INTO tab_float VALUES(123.4523,123.4523,123.4523);
92 INSERT INTO tab_float VALUES(123.456,123.456,123.456);
93 INSERT INTO tab_float VALUES(123.4,123.4,123.4);
94 INSERT INTO tab_float VALUES(1523.4,1523.4,1523.4);
95
96
97
98 #原则:
99
103
104 #三、字符型
105
131
132
133
134 CREATE TABLE tab_char(
135 c1 ENUM("a","b","c")
136
137
138 );
139
140
141 INSERT INTO tab_char VALUES("a");
142 INSERT INTO tab_char VALUES("b");
143 INSERT INTO tab_char VALUES("c");
144 INSERT INTO tab_char VALUES("m");
145 INSERT INTO tab_char VALUES("A");
146
147 SELECT * FROM tab_set;
148
149
150
151 CREATE TABLE tab_set(
152
153 s1 SET("a","b","c","d")
154
155
156
157 );
158 INSERT INTO tab_set VALUES("a");
159 INSERT INTO tab_set VALUES("A,B");
160 INSERT INTO tab_set VALUES("a,c,d");
161
162
163 #四、日期型
164
165
183
184
185 CREATE TABLE tab_date(
186 t1 DATETIME,
187 t2 TIMESTAMP
188
189 );
190
191
192
193 INSERT INTO tab_date VALUES(NOW(),NOW());
194
195 SELECT * FROM tab_date;
196
197
198 SHOW VARIABLES LIKE "time_zone";
199
200 SET time_zone="+9:00";