如何在Postgres中禁用PK变化?
如何禁用DB的PK更改?是否可以?
例如,我有一个表:
user
id name email password ...
1 Alex ... ...
2 Mark ... ...
如何禁用更改用户的可能性。
How do I disable PK changes in my db? Is it possible?
For example, I have this table:
user
id name email password ...
1 Alex ... ...
2 Mark ... ...
How to disable the possibility of changing user.id?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用数据库参考机制。创建一个虚拟表,该表引用您要保护的列,并将访问权限撤销到该表的其他用户。示例:
参考的默认模式是限制删除或更新:
另外,您可以定义触发器以放弃不需要的修改,例如
在 db<> fiddle。
You can use the database reference mechanism. Create a dummy table that references the column you want to protect and revoke the access privilege to this table for other users. Example:
The default mode of the reference is to restrict deletes or updates:
Alternatively, you can define a trigger to abandon modifications you do not want, e.g.
Test it in db<>fiddle.