gpt4 book ai didi

MySQL 复制

转载 作者:行者123 更新时间:2023-11-29 12:04:01 26 4
gpt4 key购买 nike

使用 SQLyog,我正在测试表中是否设置了正确的值。我尝试过

SELECT type_service FROM service WHERE email='test@gmail.com'

因此,只输出了一个结果。

type_service
0

为了继续测试,我尝试强制设置值1,这给出了警告

Warning

There are 2 duplicates of the row you are trying to update. Do you want to update all the duplicates?

注意:您可以通过取消选中“工具”->“首选项”->“其他”->“更新多行时提示”来关闭此警告。

但我认为我已经对 where 子句进行了限制。所以我推了"is"。结果,type_service列中的所有数据的值都变成了1。为什么?

最佳答案

表中有 2 个完全相同的重复行。 准确。这是一个友好的警告,但很可能需要通过轻微的架构更改来解决。

最简单的解决方案是更改表并添加 auto_increment 主键列。

Mysql Alter Table手册页here .

请参阅此 Webyog 常见问题解答 link .

每当我要惊扰另一张 table 时,我通常会像这样将其 stub :

create table blah
(
id int auto_increment primary key,
...
...
...
);

为了安全起见。

如果您没有 auto_increment PK,请参阅以下内容。

create table people
(
firstName varchar(40) not null,
lastName varchar(40) not null,
age int not null
);

insert people (firstName,lastName,age) values ('Kim','Billings',30),('Kim','Billings',30),('Kim','Billings',30);

select * from people;

-- this could be bad:
update people
set age=40
where firstName='Kim' and lastName='Billings';

ALTER TABLE people ADD id INT PRIMARY KEY AUTO_INCREMENT;

select * from people; -- much nicer now, schema has an id column starting at 1

-- you now at least have a way to uniquely identify a row

关于MySQL 复制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31867596/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com