如何在MySQL中的表格上保持两个列之间的完整性?
我有的列主键
和
。我想维护on Table
上的普通列Integrity
大约两列。
假设我有一个用户表和两个数据。我想在ID> ID
列和create_user
列之间具有Integrity
CREATE TABLE USER (
id varchar(10) not null,
create_user varchar(10) not null,
PRIMARY KEY (id)
);
insert into USER (id,create_user) values ('system','system');
insert into USER (id,create_user) values ('user01','system');
The result is
| id | create_user |
| -------- | ------------|
| system | system |
| user01 | system |
,如果我更新ID(主键),它没有完整性。
update USER SET id='master' WHERE id='system';
The result is
| id | create_user |
| -------- | ------------|
| master | system |
| user01 | system |
但是我想在上
表
。是否可以?我不想要其他更新queris
| id | create_user |
| -------- | ------------|
| master | master |
| user01 | master |
I have columns which are a primary key
and a plain column
on a table
. I want to maintain integrity
about two columns.
Suppose I have a user table and two datas. I want to have integrity
between a id
column and a create_user
column
CREATE TABLE USER (
id varchar(10) not null,
create_user varchar(10) not null,
PRIMARY KEY (id)
);
insert into USER (id,create_user) values ('system','system');
insert into USER (id,create_user) values ('user01','system');
The result is
| id | create_user |
| -------- | ------------|
| system | system |
| user01 | system |
If I update id(a primary key), It doesn't have integrity.
update USER SET id='master' WHERE id='system';
The result is
| id | create_user |
| -------- | ------------|
| master | system |
| user01 | system |
But I want to this on a table
. Is it possible? I don't want additional update queris
| id | create_user |
| -------- | ------------|
| master | master |
| user01 | master |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以根据需要更新任意数量的列,并使用 case 语句来决定将它们设置为什么
You can update as many columns as you like and use case statements to decide what to set them to