create table mydbemp id int auto_increment primary key empno int not null name varchar20 null age int null deptId int null charset = utf8mb3;
-- 随机生成1000条数据 INSERT INTO mydb.emp (empno, name, age, deptId) SELECT FLOOR(RAND() * 1000000) as empno, -- 生成随机的员工编号 CONCAT('Employee', FLOOR(RAND() * 1000)) as name, -- 生成随机的员工姓名 FLOOR(RAND() * 50) + 20 as age, -- 生成随机的年龄,范围20-69 FLOOR(RAND() * 10) + 1 as deptId -- 生成随机的部门编号,范围1-10 FROM (SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) a, -- 生成4个随机值 (SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) b, -- 生成4个随机值 (SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) c -- 生成4个随机值 LIMIT 1000; -- 限制生成1000条数
原文地址: https://www.cveoy.top/t/topic/czO1 著作权归作者所有。请勿转载和采集!