您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關(guān)mysql中新建表和理清表之間有什么聯(lián)系的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。
/*
Navicat MySQL Data Transfer
Source Server : localhost
Source Server Version : 50520
Source Host : localhost:3306
Source Database : gupao
Target Server Type : MYSQL
Target Server Version : 50520
File Encoding : 65001
Date: 2018-07-24 22:42:54
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for baoming
-- ----------------------------
DROP TABLE IF EXISTS `baoming`;
CREATE TABLE `baoming` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`sid` int(11) DEFAULT NULL,
`kid` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of baoming
-- ----------------------------
INSERT INTO `baoming` VALUES ('1', '1', '1');
INSERT INTO `baoming` VALUES ('2', '2', '1');
INSERT INTO `baoming` VALUES ('3', '3', '1');
INSERT INTO `baoming` VALUES ('4', '4', '2');
INSERT INTO `baoming` VALUES ('5', '5', '2');
INSERT INTO `baoming` VALUES ('6', '6', '2');
INSERT INTO `baoming` VALUES ('7', '7', '3');
INSERT INTO `baoming` VALUES ('9', '1', '3');
INSERT INTO `baoming` VALUES ('10', '3', '3');
INSERT INTO `baoming` VALUES ('11', '5', '3');
-- ----------------------------
-- Table structure for class
-- ----------------------------
DROP TABLE IF EXISTS `class`;
CREATE TABLE `class` (
`cid` int(11) NOT NULL AUTO_INCREMENT,
`level` int(11) DEFAULT NULL,
`name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`cid`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of class
-- ----------------------------
INSERT INTO `class` VALUES ('1', '1', '班級(jí)1');
INSERT INTO `class` VALUES ('2', '1', '班級(jí)2');
INSERT INTO `class` VALUES ('3', '2', '班級(jí)3');
INSERT INTO `class` VALUES ('4', '3', '班級(jí)4');
-- ----------------------------
-- Table structure for ke
-- ----------------------------
DROP TABLE IF EXISTS `ke`;
CREATE TABLE `ke` (
`kid` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`tid` int(11) DEFAULT NULL,
PRIMARY KEY (`kid`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of ke
-- ----------------------------
INSERT INTO `ke` VALUES ('1', '課程1', '2');
INSERT INTO `ke` VALUES ('2', '課程2', '1');
INSERT INTO `ke` VALUES ('3', '課程3', '5');
INSERT INTO `ke` VALUES ('4', '課程4', '5');
INSERT INTO `ke` VALUES ('5', '課程0', '0');
INSERT INTO `ke` VALUES ('6', '課程', null);
-- ----------------------------
-- Table structure for student
-- ----------------------------
DROP TABLE IF EXISTS `student`;
CREATE TABLE `student` (
`sid` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`sex` int(11) DEFAULT '1',
`cid` int(11) DEFAULT NULL,
PRIMARY KEY (`sid`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of student
-- ----------------------------
INSERT INTO `student` VALUES ('1', '學(xué)生1', '1', '1');
INSERT INTO `student` VALUES ('2', '學(xué)生2', '1', '1');
INSERT INTO `student` VALUES ('3', '學(xué)生3', '2', '1');
INSERT INTO `student` VALUES ('4', '學(xué)生4', '2', '1');
INSERT INTO `student` VALUES ('5', '學(xué)生5', '1', '2');
INSERT INTO `student` VALUES ('6', '學(xué)生6', '1', '2');
INSERT INTO `student` VALUES ('7', '學(xué)生7', '2', '2');
INSERT INTO `student` VALUES ('8', '學(xué)生8', '2', '2');
INSERT INTO `student` VALUES ('9', '學(xué)生9', '1', '3');
INSERT INTO `student` VALUES ('10', '學(xué)生0', '1', '0');
-- ----------------------------
-- Table structure for teacher
-- ----------------------------
DROP TABLE IF EXISTS `teacher`;
CREATE TABLE `teacher` (
`tid` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`sex` int(11) DEFAULT '1',
PRIMARY KEY (`tid`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of teacher
-- ----------------------------
INSERT INTO `teacher` VALUES ('1', '教授1', '1');
INSERT INTO `teacher` VALUES ('2', '教授2', '1');
INSERT INTO `teacher` VALUES ('3', '教授3', '2');
INSERT INTO `teacher` VALUES ('4', '教授4', '2');
INSERT INTO `teacher` VALUES ('5', '大教授', '1');
INSERT INTO `teacher` VALUES ('6', '助教', '2');
在上課的老師
SELECT DISTINCT t.name FROM ke
JOIN teacher AS t ON ke.tid=t.tid
老師和學(xué)生的對(duì)應(yīng)關(guān)系
SELECT * FROM ke
JOIN teacher AS t ON ke.tid=t.tid
JOIN baoming AS b ON ke.kid=b.kid
JOIN student AS s ON b.sid=s.sid
感謝各位的閱讀!關(guān)于“mysql中新建表和理清表之間有什么聯(lián)系”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。