【发布时间】:2022-12-09 19:42:10
【问题描述】:
我有两个相似的表:
CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT ,
`c1` int(11) NOT NULL DEFAULT '0',
`c2` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `idx_c1` (`c1`)
) ENGINE=InnoDB;
CREATE TABLE `t2` (
`id` int(11) NOT NULL AUTO_INCREMENT ,
`c1` int(11) NOT NULL DEFAULT '0',
`c2` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `idx_c1` (`c1`)
) ENGINE=InnoDB;
我想用随机值填充两个表:
drop procedure if exists random_records;
truncate table t1;
truncate table t2;
delimiter $$
create procedure random_records(n int)
begin
set @i=1;
set @m=100000;
while @i <= n do
insert into t1(c1,c2) values(rand()*@m,rand()*@m);
insert into t2(c1,c2) values(rand()*@m,rand()*@m);
set @i=@i+1;
end while;
end $$
delimiter ;
call random_records(100);
select * from t1 limit 10;
select * from t2 limit 10;
select count(*) from t1;
select count(*) from t2;
我不明白为什么会有很多'0'和'1' 函数 count() 为 t1 返回 210,为 t2 返回 208——还有一个谜
【问题讨论】: