Mysql学习---SQL测试题之表结构

Posted 小a玖拾柒

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mysql学习---SQL测试题之表结构相关的知识,希望对你有一定的参考价值。

创建表结果和数据准备[直接执行即可]

  1 /*
  2 Navicat MySQL Data Transfer
  3 
  4 Source Server         : ftl1012
  5 Source Server Version : 50617
  6 Source Host           : localhost:3306
  7 Source Database       : test_python
  8 
  9 Target Server Type    : MYSQL
 10 Target Server Version : 50617
 11 File Encoding         : 65001
 12 
 13 Date: 2017-12-30 13:12:57
 14 */
 15 
 16 SET FOREIGN_KEY_CHECKS=0;
 17 
 18 -- ----------------------------
 19 -- Table structure for class
 20 -- ----------------------------
 21 DROP TABLE IF EXISTS `class`;
 22 CREATE TABLE `class` (
 23   `cid` int(11) NOT NULL AUTO_INCREMENT,
 24   `caption` varchar(32) NOT NULL,
 25   PRIMARY KEY (`cid`)
 26 ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
 27 
 28 -- ----------------------------
 29 -- Records of class
 30 -- ----------------------------
 31 INSERT INTO `class` VALUES (\'1\', \'三年二班\');
 32 INSERT INTO `class` VALUES (\'2\', \'三年三班\');
 33 INSERT INTO `class` VALUES (\'3\', \'一年二班\');
 34 INSERT INTO `class` VALUES (\'4\', \'二年九班\');
 35 
 36 -- ----------------------------
 37 -- Table structure for course
 38 -- ----------------------------
 39 DROP TABLE IF EXISTS `course`;
 40 CREATE TABLE `course` (
 41   `cid` int(11) NOT NULL AUTO_INCREMENT,
 42   `cname` varchar(32) NOT NULL,
 43   `teacher_id` int(11) NOT NULL,
 44   PRIMARY KEY (`cid`),
 45   KEY `fk_course_teacher` (`teacher_id`),
 46   CONSTRAINT `fk_course_teacher` FOREIGN KEY (`teacher_id`) REFERENCES `teacher` (`tid`)
 47 ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
 48 
 49 -- ----------------------------
 50 -- Records of course
 51 -- ----------------------------
 52 INSERT INTO `course` VALUES (\'1\', \'生物\', \'1\');
 53 INSERT INTO `course` VALUES (\'2\', \'物理\', \'2\');
 54 INSERT INTO `course` VALUES (\'3\', \'体育\', \'3\');
 55 INSERT INTO `course` VALUES (\'4\', \'美术\', \'2\');
 56 
 57 -- ----------------------------
 58 -- Table structure for score
 59 -- ----------------------------
 60 DROP TABLE IF EXISTS `score`;
 61 CREATE TABLE `score` (
 62   `sid` int(11) NOT NULL AUTO_INCREMENT,
 63   `student_id` int(11) NOT NULL,
 64   `course_id` int(11) NOT NULL,
 65   `num` int(11) NOT NULL,
 66   PRIMARY KEY (`sid`),
 67   KEY `fk_score_student` (`student_id`),
 68   KEY `fk_score_course` (`course_id`),
 69   CONSTRAINT `fk_score_course` FOREIGN KEY (`course_id`) REFERENCES `course` (`cid`),
 70   CONSTRAINT `fk_score_student` FOREIGN KEY (`student_id`) REFERENCES `student` (`sid`)
 71 ) ENGINE=InnoDB AUTO_INCREMENT=53 DEFAULT CHARSET=utf8;
 72 
 73 -- ----------------------------
 74 -- Records of score
 75 -- ----------------------------
 76 INSERT INTO `score` VALUES (\'1\', \'1\', \'1\', \'10\');
 77 INSERT INTO `score` VALUES (\'2\', \'1\', \'2\', \'9\');
 78 INSERT INTO `score` VALUES (\'5\', \'1\', \'4\', \'66\');
 79 INSERT INTO `score` VALUES (\'6\', \'2\', \'1\', \'8\');
 80 INSERT INTO `score` VALUES (\'8\', \'2\', \'3\', \'68\');
 81 INSERT INTO `score` VALUES (\'9\', \'2\', \'4\', \'99\');
 82 INSERT INTO `score` VALUES (\'10\', \'3\', \'1\', \'77\');
 83 INSERT INTO `score` VALUES (\'11\', \'3\', \'2\', \'66\');
 84 INSERT INTO `score` VALUES (\'12\', \'3\', \'3\', \'87\');
 85 INSERT INTO `score` VALUES (\'13\', \'3\', \'4\', \'99\');
 86 INSERT INTO `score` VALUES (\'14\', \'4\', \'1\', \'79\');
 87 INSERT INTO `score` VALUES (\'15\', \'4\', \'2\', \'11\');
 88 INSERT INTO `score` VALUES (\'16\', \'4\', \'3\', \'67\');
 89 INSERT INTO `score` VALUES (\'17\', \'4\', \'4\', \'100\');
 90 INSERT INTO `score` VALUES (\'18\', \'5\', \'1\', \'79\');
 91 INSERT INTO `score` VALUES (\'19\', \'5\', \'2\', \'11\');
 92 INSERT INTO `score` VALUES (\'20\', \'5\', \'3\', \'67\');
 93 INSERT INTO `score` VALUES (\'21\', \'5\', \'4\', \'100\');
 94 INSERT INTO `score` VALUES (\'22\', \'6\', \'1\', \'9\');
 95 INSERT INTO `score` VALUES (\'23\', \'6\', \'2\', \'100\');
 96 INSERT INTO `score` VALUES (\'24\', \'6\', \'3\', \'67\');
 97 INSERT INTO `score` VALUES (\'25\', \'6\', \'4\', \'100\');
 98 INSERT INTO `score` VALUES (\'26\', \'7\', \'1\', \'9\');
 99 INSERT INTO `score` VALUES (\'27\', \'7\', \'2\', \'100\');
100 INSERT INTO `score` VALUES (\'28\', \'7\', \'3\', \'67\');
101 INSERT INTO `score` VALUES (\'29\', \'7\', \'4\', \'88\');
102 INSERT INTO `score` VALUES (\'30\', \'8\', \'1\', \'9\');
103 INSERT INTO `score` VALUES (\'31\', \'8\', \'2\', \'100\');
104 INSERT INTO `score` VALUES (\'32\', \'8\', \'3\', \'67\');
105 INSERT INTO `score` VALUES (\'33\', \'8\', \'4\', \'88\');
106 INSERT INTO `score` VALUES (\'34\', \'9\', \'1\', \'91\');
107 INSERT INTO `score` VALUES (\'35\', \'9\', \'2\', \'88\');
108 INSERT INTO `score` VALUES (\'36\', \'9\', \'3\', \'67\');
109 INSERT INTO `score` VALUES (\'37\', \'9\', \'4\', \'22\');
110 INSERT INTO `score` VALUES (\'38\', \'10\', \'1\', \'90\');
111 INSERT INTO `score` VALUES (\'39\', \'10\', \'2\', \'77\');
112 INSERT INTO `score` VALUES (\'40\', \'10\', \'3\', \'43\');
113 INSERT INTO `score` VALUES (\'41\', \'10\', \'4\', \'87\');
114 INSERT INTO `score` VALUES (\'42\', \'11\', \'1\', \'90\');
115 INSERT INTO `score` VALUES (\'43\', \'11\', \'2\', \'77\');
116 INSERT INTO `score` VALUES (\'44\', \'11\', \'3\', \'43\');
117 INSERT INTO `score` VALUES (\'45\', \'11\', \'4\', \'87\');
118 INSERT INTO `score` VALUES (\'46\', \'12\', \'1\', \'90\');
119 INSERT INTO `score` VALUES (\'47\', \'12\', \'2\', \'77\');
120 INSERT INTO `score` VALUES (\'48\', \'12\', \'3\', \'43\');
121 INSERT INTO `score` VALUES (\'49\', \'12\', \'4\', \'87\');
122 INSERT INTO `score` VALUES (\'52\', \'13\', \'3\', \'87\');
123 
124 -- ----------------------------
125 -- Table structure for student
126 -- ----------------------------
127 DROP TABLE IF EXISTS `student`;
128 CREATE TABLE `student` (
129   `sid` int(11) NOT NULL AUTO_INCREMENT,
130   `gender` char(1) NOT NULL,
131   `class_id` int(11) NOT NULL,
132   `sname` varchar(32) NOT NULL,
133   PRIMARY KEY (`sid`),
134   KEY `fk_class` (`class_id`),
135   CONSTRAINT `fk_class` FOREIGN KEY (`class_id`) REFERENCES `class` (`cid`)
136 ) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8;
137 
138 -- ----------------------------
139 -- Records of student
140 -- ----------------------------
141 INSERT INTO `student` VALUES (\'1\', \'\', \'1\', \'理解\');
142 INSERT INTO `student` VALUES (\'2\', \'\', \'1Mysql原理篇之表空间---05

MySQL之表操作

MySQL数据库之表的增删改查

MYSQL之表操作

mysql学习第6篇:数据库之表与表之间的关系

mysql颠覆实战学习记录 :用户充值功能实现:钱的安全性之表锁 12