前言:
一:数据准备
员工表emp 和部门表 dept
--分别创建部门和员工表,并实现一对多关系 DROP TABLE dept; CREATE TABLE `dept`( `d_id` INT(5) PRIMARY KEY AUTO_INCREMENT COMMENT ‘这是部门id主键自增长‘, `d_name` VARCHAR(30) NOT NULL UNIQUE COMMENT ‘这是部门名称唯一非空‘ ); CREATE TABLE `emp`( `e_id` INT PRIMARY KEY AUTO_INCREMENT COMMENT ‘这是员工表的主键自增长‘, `e_uname` VARCHAR(10) NOT NULL UNIQUE COMMENT ‘这是登录名‘, `e_name` VARCHAR(20) NOT NULL COMMENT ‘这是真实姓名‘, `e_pwd` VARCHAR(20) DEFAULT ‘123456‘ COMMENT ‘这是密码默认为123456‘, `e_d_id` INT(5), CONSTRAINT `emp_fk` FOREIGN KEY (`e_d_id`) REFERENCES dept (`d_id`) ); --准备数据 --先给dept录入测试数据 INSERT INTO dept VALUES(NULL,‘财务部‘),(NULL,‘技术部‘),(NULL,‘营销部‘),(NULL,‘采购部‘),(NULL,‘市场部‘); INSERT INTO dept VALUES(NULL,‘行政部‘),(NULL,‘后勤部‘),(NULL,‘总经办‘),(NULL,‘人事部‘),(NULL,‘策划部‘); --给emp录入测试数据 INSERT INTO emp (e_uname,e_name,e_d_id)VALUES(‘lqd‘,‘刘强东‘,20); INSERT INTO emp (e_uname,e_name,e_d_id)VALUES(‘mht‘,‘马化腾‘,17); INSERT INTO emp (e_uname,e_name,e_d_id)VALUES(‘my‘,‘马云‘,8); INSERT INTO emp (e_uname,e_name,e_d_id)VALUES(‘lyf‘,‘刘亦菲‘,16); INSERT INTO emp (e_uname,e_name,e_d_id)VALUES(‘wjl‘,‘王健林‘,9); INSERT INTO emp (e_uname,e_name,e_d_id)VALUES(‘zzt‘,‘章泽天‘,17); INSERT INTO emp (e_uname,e_name,e_d_id)VALUES(‘ldh‘,‘刘德华‘,10); INSERT INTO emp (e_uname,e_name,e_d_id)VALUES(‘dl‘,‘丁磊‘,16); INSERT INTO emp (e_uname,e_name,e_d_id)VALUES(‘zhy‘,‘周鸿祎‘,18); INSERT INTO emp (e_uname,e_name,e_d_id)VALUES(‘zzy‘,‘章子怡‘,9); INSERT INTO emp (e_uname,e_name,e_d_id)VALUES(‘abm‘,‘奥巴马‘,19); INSERT INTO emp (e_uname,e_name,e_d_id)VALUES(‘zjl‘,‘周杰伦‘,7); INSERT INTO emp (e_uname,e_name,e_d_id)VALUES(‘zcy‘,‘张朝阳‘,16); INSERT INTO emp (e_uname,e_name,e_d_id)VALUES(‘zj‘,‘周洁‘,19); INSERT INTO emp (e_uname,e_name,e_d_id)VALUES(‘syp‘,‘苏有朋‘,20); INSERT INTO emp (e_uname,e_name,e_d_id)VALUES(‘fxg‘,‘冯小刚‘,20); INSERT INTO emp (e_uname,e_name,e_d_id)VALUES(‘wsc‘,‘王思聪‘,10); INSERT INTO emp (e_uname,e_name,e_d_id)VALUES(‘hxn‘,‘韩晓诺‘,19); INSERT INTO emp (e_uname,e_name,e_d_id)VALUES(‘zy‘,‘曾洋‘,7); INSERT INTO emp (e_uname,e_name,e_d_id)VALUES(‘hh‘,‘韩寒‘,6); INSERT INTO emp (e_uname,e_name,e_d_id)VALUES(‘mbp‘,‘姆巴佩‘,17); INSERT INTO emp (e_uname,e_name,e_d_id)VALUES(‘gjm‘,‘郭敬明‘,7); INSERT INTO emp (e_uname,e_name,e_d_id)VALUES(‘wsc‘,‘王宝强‘,10); INSERT INTO emp (e_uname,e_name,e_d_id)VALUES(‘xjy‘,‘许家印‘,6);
准备数据dept和emp
二:
原文地址:https://www.cnblogs.com/wdmlsx/p/9270123.html
时间: 2024-10-13 22:56:38