赞
踩
一、数字类型
A:整型
mysql> show create table a\G
*************************** 1. row ***************************
Table: a
Create Table: CREATE TABLE `a` (
`a` int(10) unsigned DEFAULT NULL,
`b` int(10) unsigned DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
这里的10,表示什么意思
本身没有意义,只有与zerofill配合在一起,才会起作用
mysql> create table c( a int(3) zerofill,b int(3) zerofill);
Query OK, 0 rows affected (0.16 sec)
mysql> insert into c select 1,2;
Query OK, 1 row affected (0.00 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> select * from c;
+------+------+
| a | b |
+------+------+
| 001 | 002 |
+------+------+
1 row in set (0.00 sec)
mysql> select a-b from c;
ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '(`testDB`.`c`.`a` - `testDB`.`c`.`b`)'
mysql> insert into c select 1111;
ERROR 1136 (21S01): Column count doesn't match value count at row 1 (列计数不匹配值计数)
INT类型的属性:
UNSIGNED/SIGNED: 是否有符号
ZEROFILL: 显示属性,值不做任何修改
Auto_INCREMENT: 自增,每张表一个自增字段,该自增字段,必须是索引的一部分
mysql> create table d ( a int auto_increment);
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key (自增字段必须是一个索引(key),否则会报错)
mysql> create table d ( a int auto_increment primary key);
Query OK, 0 rows affected (0.14 sec)
mysql> insert into d select NULL;
Query OK, 1 row affected (0.00 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> select * from d;
+---+
| a |
+---+
| 1 |
+---+
1 row in set (0.00 sec)
总结:
1、推荐不要试用unsigned,unsigned可能会有溢出现象发生
2、自增int类型,主键建议使用bigint类型
TRADITIONAL模式:严格模式,当向mysql数据库插入数据时,进行数据的严格校
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。