可以根据数字类型来设计
alter table 表名 add 新字段名 bigserial;
alter table 表名 add constraint 约束名 unique (新字段名);
例如:
|
alter table tt add zi bigserial;
alter table tt add constraint tb_111 unique (zi); |
行数不多可以使用serial而非bigserial,无论使用哪种格式一定要记得增加唯一约束。
目的:
①防止后期字段值重复。
②查询加速
alter table 表名 add 新字段名 serial;
alter table 表名 add constraint 约束名 unique (新字段名);
附:
|
smallint |
2字节 |
小范围整数 |
-32768 to +32767 |
|
integer |
4字节 |
整数的典型选择 |
-2147483648 to +2147483647 |
|
bigint |
8字节 |
大范围整数 |
-9223372036854775808 to +9223372036854775807 |
|
decimal |
可变 |
用户指定精度,精确 |
最高小数点前131072位,以及小数点后16383位 |
|
numeric |
可变 |
用户指定精度,精确 |
最高小数点前131072位,以及小数点后16383位 |
|
real |
4字节 |
可变精度,不精确 |
6位十进制精度 |
|
double precision |
8字节 |
可变精度,不精确 |
15位十进制精度 |
|
smallserial |
2字节 |
自动增加的小整数 |
1到32767 |
|
serial |
4字节 |
自动增加的整数 |
1到2147483647 |
|
bigserial |
8字节 |
自动增长的大整数 |
1到9223372036854775807 |
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69994931/viewspace-2888582/
,如需转载,请注明出处,否则将追究法律责任。