当我将列的大小从BIGINT(11)更改为BIGINT(20)时,MySql表列删除了其AI标志

时间:2017-06-03 08:22:43

标签: mysql sql mysql-workbench

我有一个表名file_upload 它的列upload_id为BIGINT(11)AI PK NOT NULL 当我将表格列大小更改为BIGINT(20)时,AI标记被删除, 每当我改变列中的任何内容时,我是否应该为列提供新的定义?

1 个答案:

答案 0 :(得分:0)

只有一点点说明。 BIGINT(10) BIGINT(20)之间没有真正的区别。您可以始终存储相同的值。大小如果仅与 ZEROFILL 一起使用。

参见我的样本

mysql> CREATE TABLE `bigints` (
    ->   `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
    ->   `bigint1` BIGINT(1) UNSIGNED DEFAULT NULL,
    ->   `bigint10` BIGINT(10) UNSIGNED ZEROFILL DEFAULT NULL,
    ->   `bigint20` BIGINT(20) UNSIGNED ZEROFILL DEFAULT NULL,
    ->   PRIMARY KEY (`id`)
    -> ) ENGINE=INNODB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0,04 sec)

mysql>
mysql> INSERT INTO `bigints` (`id`, `bigint1`, `bigint10`, `bigint20`)
    -> VALUES
    ->     (1, 1, 1, 1),
    ->     (2, 100, 100, 100),
    ->     (3, 1000000000, 1000000000, 1000000000),
    ->     (4, 18446744073709551615, 18446744073709551615, 18446744073709551615);
Query OK, 4 rows affected (0,01 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> SELECT * from bigints;
+----+----------------------+----------------------+----------------------+
| id | bigint1              | bigint10             | bigint20             |
+----+----------------------+----------------------+----------------------+
|  1 |                    1 |           0000000001 | 00000000000000000001 |
|  2 |                  100 |           0000000100 | 00000000000000000100 |
|  3 |           1000000000 |           1000000000 | 00000000001000000000 |
|  4 | 18446744073709551615 | 18446744073709551615 | 18446744073709551615 |
+----+----------------------+----------------------+----------------------+
4 rows in set (0,01 sec)

mysql>