如何防止主串行主键被不按顺序更新的数字? [英] How to prevent primary serial primary key from being updated with number not in sequence?

查看:71
本文介绍了如何防止主串行主键被不按顺序更新的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CREATE TABLE u_account (
Jid serial primary key,
score int4
);

当我这样更新主键时,主键工作正常(可以自行更新);

The primary key works fine (updates itself) ok when I update it like this;

INSERT INTO u_account ('score') VALUES ('122233344');

但是当我插入这样的值时;

However when I insert a value like this;

INSERT INTO u_account VALUES ('122233344');

这将更新主键;

我不希望主键接受除了应该输入的数字之外的其他任何东西.

I don't want the primary key to accept anything other than the number that is supposed to be coming next.

以前有人为我设置了它,以便我输入这段代码;

Someone had set it up for me before so that if I put in this code;

INSERT INTO u_account VALUES ('122233344');

它将忽略主键,仅更新分数.

it would ignore the primary key and just update score.

请帮助.

推荐答案

您可以使用"DEFAULT"在主键字段中输入正确的值,例如:

You can use "DEFAULT" to put the correct value in the primary key field, eg:

INSERT INTO u_account VALUES (DEFAULT, '122233344');

这篇关于如何防止主串行主键被不按顺序更新的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆