postgresql修改字段约束

asflsf 2014-11-21 02:49:04
最近刚开始使用postgreSQL ,请教一如何为列添加自增约束呢?
...全文
1015 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
w_xxxbbb 2015-01-26
  • 打赏
  • 举报
回复
楼上正解,1、可以直接把字段类型设置为serial;2、也可以自己建立序列,然后加载在表的一个字段上。两种方式都是自增长的,第二种方式更加人性化点,可以重新设置序列。
huguangshanse00 2014-11-22
  • 打赏
  • 举报
回复
postgres 支持serial 数据类型,字段定义为serial后将自动创建1个序列生成器sequence。 示例: postgres=# \d No relations found. postgres=# create table test1(id1 serial, id2 int); CREATE TABLE postgres=# insert into test1(id2) values(1); INSERT 0 1 postgres=# insert into test1(id2) values(2); INSERT 0 1 postgres=# select * from test1; id1 | id2 -----+----- 1 | 1 2 | 2 (2 rows)

951

社区成员

发帖
与我相关
我的任务
社区描述
PostgreSQL相关内容讨论
sql数据库数据库架构 技术论坛(原bbs)
社区管理员
  • PostgreSQL社区
  • yang_z_1
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧