理论图谱:
MySQL数据库实例:
1.创建数据库:
mysql> create database db_test; Query OK, 1 row affected (0.01 sec)
2.使用数据库:
mysql> use db_test; Database changed
3.创建表、添加数据:
CREATE TABLE `tb_dept` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT ‘部门主键‘, `deptName` varchar(30) DEFAULT NULL COMMENT ‘部门名称‘, `locAdd` varchar(40) DEFAULT NULL COMMENT ‘楼层‘, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; CREATE TABLE `tb_emp` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT ‘员工主键‘, `name` varchar(20) DEFAULT NULL COMMENT ‘员工姓名‘, `deptId` int(11) DEFAULT NULL COMMENT ‘部门外键‘, PRIMARY KEY (`id`), KEY `fk_dept_id` (`deptId`) #CONSTRAINT `fk_dept_id` FOREIGN KEY (`deptId`) REFERENCES `tb_dept` (`id`) COMMENT ‘部门外键设置, 已经注释掉。‘ ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; INSERT INTO `tb_dept` VALUES (‘1‘, ‘RD‘, ‘11‘); INSERT INTO `tb_dept` VALUES (‘2‘, ‘HR‘, ‘12‘); INSERT INTO `tb_dept` VALUES (‘3‘, ‘MK‘, ‘13‘); INSERT INTO `tb_dept` VALUES (‘4‘, ‘MIS‘, ‘14‘); INSERT INTO `tb_dept` VALUES (‘5‘, ‘FD‘, ‘15‘); INSERT INTO `tb_emp` VALUES (‘1‘, ‘张三‘, ‘1‘); INSERT INTO `tb_emp` VALUES (‘2‘, ‘李四‘, ‘1‘); INSERT INTO `tb_emp` VALUES (‘3‘, ‘王二‘, ‘1‘); INSERT INTO `tb_emp` VALUES (‘4‘, ‘麻子‘, ‘2‘); INSERT INTO `tb_emp` VALUES (‘5‘, ‘小马‘, ‘2‘); INSERT INTO `tb_emp` VALUES (‘6‘, ‘马旭‘, ‘3‘); INSERT INTO `tb_emp` VALUES (‘7‘, ‘小丁‘, ‘4‘); INSERT INTO `tb_emp` VALUES (‘8‘, ‘小西‘, ‘51‘);
时间: 2024-10-17 05:44:00