• mysql岗位实习----教务系统管理


    教务管理系统

    一、DDL

    1. CREATE TABLE `users` (
    2. `user_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '用户ID',
    3. `username` varchar(50) NOT NULL COMMENT '用户名',
    4. `password` varchar(255) NOT NULL COMMENT '密码',
    5. `gender` enum('男','女') NOT NULL COMMENT '性别',
    6. `email` varchar(100) DEFAULT NULL COMMENT '邮箱',
    7. PRIMARY KEY (`user_id`),
    8. UNIQUE KEY `username` (`username`),
    9. UNIQUE KEY `email` (`email`)
    10. ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
    11. CREATE TABLE `userroles` (
    12. `user_id` int(11) NOT NULL COMMENT '用户ID',
    13. `role_id` int(11) NOT NULL COMMENT '角色ID',
    14. `created_at` datetime NOT NULL,
    15. PRIMARY KEY (`user_id`),
    16. KEY `role_id` (`role_id`),
    17. CONSTRAINT `userroles_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
    18. CONSTRAINT `userroles_ibfk_2` FOREIGN KEY (`role_id`) REFERENCES `roles` (`role_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
    19. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    20. CREATE TABLE `teachers` (
    21. `teacher_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '教师ID',
    22. `user_id` int(11) NOT NULL COMMENT '关联的用户ID',
    23. `subject` varchar(100) NOT NULL COMMENT '教学科目',
    24. `qualification` varchar(255) DEFAULT NULL COMMENT '教师资质',
    25. PRIMARY KEY (`teacher_id`),
    26. KEY `user_id` (`user_id`),
    27. CONSTRAINT `teachers_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
    28. ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
    29. CREATE TABLE `students` (
    30. `student_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '学生ID',
    31. `user_id` int(11) NOT NULL COMMENT '关联的用户ID',
    32. `class` varchar(50) NOT NULL COMMENT '班级',
    33. `year_of_entry` year(4) NOT NULL COMMENT '入学年份',
    34. PRIMARY KEY (`student_id`),
    35. KEY `user_id` (`user_id`),
    36. CONSTRAINT `students_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
    37. ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
    38. CREATE TABLE `roles` (
    39. `role_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '角色ID',
    40. `role_name` varchar(50) NOT NULL COMMENT '角色名称',
    41. `created_at` datetime NOT NULL,
    42. PRIMARY KEY (`role_id`),
    43. UNIQUE KEY `role_name` (`role_name`)
    44. ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
    45. CREATE TABLE `grades` (
    46. `grade_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '成绩ID',
    47. `student_id` int(11) NOT NULL COMMENT '学生ID',
    48. `course_id` int(11) NOT NULL COMMENT '课程ID',
    49. `grade` decimal(5,2) NOT NULL COMMENT '成绩',
    50. PRIMARY KEY (`grade_id`),
    51. KEY `student_id` (`student_id`),
    52. KEY `course_id` (`course_id`),
    53. CONSTRAINT `grades_ibfk_1` FOREIGN KEY (`student_id`) REFERENCES `students` (`student_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
    54. CONSTRAINT `grades_ibfk_2` FOREIGN KEY (`course_id`) REFERENCES `courses` (`course_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
    55. ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
    56. CREATE TABLE `courses` (
    57. `course_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '课程ID',
    58. `course_name` varchar(100) NOT NULL COMMENT '课程名称',
    59. `course_code` varchar(50) NOT NULL COMMENT '课程代码',
    60. `description` text COMMENT '课程描述',
    61. PRIMARY KEY (`course_id`),
    62. UNIQUE KEY `course_name` (`course_name`),
    63. UNIQUE KEY `course_code` (`course_code`)
    64. ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

    二、DML

    1. INSERT INTO `users` VALUES (1, '喜羊羊', '123', '男', 'xiyangyang@example.com');
    2. INSERT INTO `users` VALUES (2, '美羊羊', '123', '女', 'meiyangyang@example.com');
    3. INSERT INTO `users` VALUES (3, '灰太狼', '123', '男', 'huitailang@example.com');
    4. INSERT INTO `userroles` VALUES (1, 1, '2020-1-1 00:00:00');
    5. INSERT INTO `userroles` VALUES (2, 2, '2020-1-1 00:00:00');
    6. INSERT INTO `userroles` VALUES (3, 3, '2020-1-1 00:00:00');
    7. INSERT INTO `teachers` VALUES (1, 2, '数学', '高级教师');
    8. INSERT INTO `teachers` VALUES (2, 2, 'mysql', '特级教师');
    9. INSERT INTO `teachers` VALUES (3, 2, 'web', '特级教师');
    10. INSERT INTO `students` VALUES (1, 2, '一班', '2020');
    11. INSERT INTO `students` VALUES (2, 2, '二班', '2021');
    12. INSERT INTO `students` VALUES (3, 2, '三班', '2022');
    13. INSERT INTO `roles` VALUES (1, '管理员', '2020-1-1 00:00:00');
    14. INSERT INTO `roles` VALUES (2, '教师', '2020-1-1 00:00:00');
    15. INSERT INTO `roles` VALUES (3, '学生', '2020-1-1 00:00:00');
    16. INSERT INTO `grades` VALUES (1, 2, 2, 95.00);
    17. INSERT INTO `grades` VALUES (2, 1, 3, 92.00);
    18. INSERT INTO `grades` VALUES (3, 3, 1, 100.00);
    19. INSERT INTO `grades` VALUES (4, 2, 3, 98.00);
    20. INSERT INTO `grades` VALUES (5, 3, 3, 100.00);
    21. INSERT INTO `grades` VALUES (6, 1, 2, 100.00);
    22. INSERT INTO `courses` VALUES (1, '数学', '0000', '计算量大');
    23. INSERT INTO `courses` VALUES (2, 'mysql', '1111', '代码数量复杂');
    24. INSERT INTO `courses` VALUES (3, 'web', '6666', '花样多');

    三、模型图和ER图

     

    四、DQL

  • 相关阅读:
    为全志D1/RISCV64设备移植openwrt-22.03系统
    vscode使用docker 简介、步骤
    408王道计算机组成原理强化——中央处理器及大题解构
    解决webstrom ERROR in [eslint] ESLint is not a constructor
    有一门课不及格的学生
    实现ESP8266模块的socket接口,以提供MQTTClient库底层数据收发接口
    golang JWT原理介绍
    回顾总结之数据结构:3 链表
    【计算机网络】子网掩码、子网划分
    黑白影片智能上色,复原历史重现经典
  • 原文地址:https://blog.csdn.net/2301_80151755/article/details/140001680