diff --git "a/07 \351\231\210\346\235\260/20230910 \350\261\206\347\223\243.md" "b/07 \351\231\210\346\235\260/20230910 \350\261\206\347\223\243.md" new file mode 100644 index 0000000000000000000000000000000000000000..c0247e49a92346c3d2b9829d8ecb5516eccc79bc --- /dev/null +++ "b/07 \351\231\210\346\235\260/20230910 \350\261\206\347\223\243.md" @@ -0,0 +1,243 @@ +# 笔记 + +1. 概念模型CDM,ER图,人类角度 +2. 逻辑模型LDM,计算机角度 +3. 物理模型PDM,从具体数据库角度 +4. 生成DDL,数据定义语言 +5. 命名的所有名称,Code不要包涵 - 和 , ,最后标点符号只用_ 。 + + + + + +# 代码 + +```mysql +/* + Navicat Premium Data Transfer + + Source Server : lijunyang + Source Server Type : MySQL + Source Server Version : 50742 + Source Host : localhost:3306 + Source Schema : bbookkss + + Target Server Type : MySQL + Target Server Version : 50742 + File Encoding : 65001 + + Date: 10/09/2023 16:56:08 +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for book +-- ---------------------------- +DROP TABLE IF EXISTS `book`; +CREATE TABLE `book` ( + `b_id` int(11) NOT NULL AUTO_INCREMENT, + `ty_id` int(11) NOT NULL, + `bo_id` int(11) NOT NULL, + `re_id` int(11) NOT NULL, + `b_name` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, + `b_money` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + PRIMARY KEY (`b_id`) USING BTREE, + INDEX `FK_Relationship_7`(`ty_id`) USING BTREE, + INDEX `FK_Relationship_8`(`bo_id`) USING BTREE, + INDEX `FK_Relationship_9`(`re_id`) USING BTREE, + CONSTRAINT `FK_Relationship_7` FOREIGN KEY (`ty_id`) REFERENCES `typee` (`ty_id`) ON DELETE RESTRICT ON UPDATE RESTRICT, + CONSTRAINT `FK_Relationship_8` FOREIGN KEY (`bo_id`) REFERENCES `borrow` (`bo_id`) ON DELETE RESTRICT ON UPDATE RESTRICT, + CONSTRAINT `FK_Relationship_9` FOREIGN KEY (`re_id`) REFERENCES `guihuan` (`re_id`) ON DELETE RESTRICT ON UPDATE RESTRICT +) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of book +-- ---------------------------- +INSERT INTO `book` VALUES (1, 1, 1, 1, '少林足球', '50元'); +INSERT INTO `book` VALUES (2, 1, 2, 2, '功夫', '58元'); +INSERT INTO `book` VALUES (3, 2, 3, 3, '无敌', '11元'); + +-- ---------------------------- +-- Table structure for borrow +-- ---------------------------- +DROP TABLE IF EXISTS `borrow`; +CREATE TABLE `borrow` ( + `bo_id` int(11) NOT NULL AUTO_INCREMENT, + `us_id` int(11) NOT NULL, + `bo_time` time NULL DEFAULT NULL, + PRIMARY KEY (`bo_id`) USING BTREE, + INDEX `FK_Relationship_2`(`us_id`) USING BTREE, + CONSTRAINT `FK_Relationship_2` FOREIGN KEY (`us_id`) REFERENCES `user` (`us_id`) ON DELETE RESTRICT ON UPDATE RESTRICT +) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of borrow +-- ---------------------------- +INSERT INTO `borrow` VALUES (1, 1, '22:00:00'); +INSERT INTO `borrow` VALUES (2, 2, '16:26:54'); +INSERT INTO `borrow` VALUES (3, 3, '16:27:11'); +INSERT INTO `borrow` VALUES (4, 4, '16:27:35'); + +-- ---------------------------- +-- Table structure for floor +-- ---------------------------- +DROP TABLE IF EXISTS `floor`; +CREATE TABLE `floor` ( + `fl_id` int(11) NOT NULL AUTO_INCREMENT, + `fl_name` varchar(5) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, + PRIMARY KEY (`fl_id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of floor +-- ---------------------------- +INSERT INTO `floor` VALUES (1, '1楼'); +INSERT INTO `floor` VALUES (2, '2楼'); +INSERT INTO `floor` VALUES (3, '3楼'); +INSERT INTO `floor` VALUES (4, '4楼'); +INSERT INTO `floor` VALUES (5, '5楼'); + +-- ---------------------------- +-- Table structure for guihuan +-- ---------------------------- +DROP TABLE IF EXISTS `guihuan`; +CREATE TABLE `guihuan` ( + `re_id` int(11) NOT NULL AUTO_INCREMENT, + `us_id` int(11) NOT NULL, + `re_time` time NULL DEFAULT NULL, + PRIMARY KEY (`re_id`) USING BTREE, + INDEX `FK_Relationship_3`(`us_id`) USING BTREE, + CONSTRAINT `FK_Relationship_3` FOREIGN KEY (`us_id`) REFERENCES `user` (`us_id`) ON DELETE RESTRICT ON UPDATE RESTRICT +) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of guihuan +-- ---------------------------- +INSERT INTO `guihuan` VALUES (1, 1, '16:27:58'); +INSERT INTO `guihuan` VALUES (2, 2, '13:28:04'); +INSERT INTO `guihuan` VALUES (3, 3, '16:28:13'); +INSERT INTO `guihuan` VALUES (4, 4, '09:28:18'); + +-- ---------------------------- +-- Table structure for library +-- ---------------------------- +DROP TABLE IF EXISTS `library`; +CREATE TABLE `library` ( + `li_id` int(11) NOT NULL AUTO_INCREMENT, + `li_name` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, + PRIMARY KEY (`li_id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of library +-- ---------------------------- +INSERT INTO `library` VALUES (1, '宇宙图书馆'); + +-- ---------------------------- +-- Table structure for relationship_4 +-- ---------------------------- +DROP TABLE IF EXISTS `relationship_4`; +CREATE TABLE `relationship_4` ( + `fl_id` int(11) NOT NULL, + `b_id` int(11) NOT NULL, + PRIMARY KEY (`fl_id`, `b_id`) USING BTREE, + INDEX `FK_Relationship_6`(`b_id`) USING BTREE, + CONSTRAINT `FK_Relationship_4` FOREIGN KEY (`fl_id`) REFERENCES `floor` (`fl_id`) ON DELETE RESTRICT ON UPDATE RESTRICT, + CONSTRAINT `FK_Relationship_6` FOREIGN KEY (`b_id`) REFERENCES `book` (`b_id`) ON DELETE RESTRICT ON UPDATE RESTRICT +) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of relationship_4 +-- ---------------------------- +INSERT INTO `relationship_4` VALUES (1, 1); +INSERT INTO `relationship_4` VALUES (2, 2); +INSERT INTO `relationship_4` VALUES (2, 3); + +-- ---------------------------- +-- Table structure for relationship_5 +-- ---------------------------- +DROP TABLE IF EXISTS `relationship_5`; +CREATE TABLE `relationship_5` ( + `b_id` int(11) NOT NULL, + `st_id` int(11) NOT NULL, + PRIMARY KEY (`b_id`, `st_id`) USING BTREE, + INDEX `FK_Relationship_10`(`st_id`) USING BTREE, + CONSTRAINT `FK_Relationship_10` FOREIGN KEY (`st_id`) REFERENCES `staff` (`st_id`) ON DELETE RESTRICT ON UPDATE RESTRICT, + CONSTRAINT `FK_Relationship_5` FOREIGN KEY (`b_id`) REFERENCES `book` (`b_id`) ON DELETE RESTRICT ON UPDATE RESTRICT +) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of relationship_5 +-- ---------------------------- +INSERT INTO `relationship_5` VALUES (1, 1); +INSERT INTO `relationship_5` VALUES (2, 1); +INSERT INTO `relationship_5` VALUES (3, 3); + +-- ---------------------------- +-- Table structure for staff +-- ---------------------------- +DROP TABLE IF EXISTS `staff`; +CREATE TABLE `staff` ( + `st_id` int(11) NOT NULL AUTO_INCREMENT, + `li_id` int(11) NOT NULL, + `st_name` varchar(4) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, + `st_sex` varchar(1) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `st_age` varchar(3) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + PRIMARY KEY (`st_id`) USING BTREE, + INDEX `FK_Relationship_1`(`li_id`) USING BTREE, + CONSTRAINT `FK_Relationship_1` FOREIGN KEY (`li_id`) REFERENCES `library` (`li_id`) ON DELETE RESTRICT ON UPDATE RESTRICT +) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of staff +-- ---------------------------- +INSERT INTO `staff` VALUES (1, 1, '张三', '男', '11'); +INSERT INTO `staff` VALUES (2, 1, '李四', '男', '23'); +INSERT INTO `staff` VALUES (3, 1, '王五', '男', '12'); +INSERT INTO `staff` VALUES (4, 1, '赵六', '男', '11'); + +-- ---------------------------- +-- Table structure for typee +-- ---------------------------- +DROP TABLE IF EXISTS `typee`; +CREATE TABLE `typee` ( + `ty_id` int(11) NOT NULL AUTO_INCREMENT, + `ty_name` varchar(9) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, + PRIMARY KEY (`ty_id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of typee +-- ---------------------------- +INSERT INTO `typee` VALUES (1, '搞笑'); +INSERT INTO `typee` VALUES (2, '恐怖'); +INSERT INTO `typee` VALUES (3, '综艺'); +INSERT INTO `typee` VALUES (4, '日常'); +INSERT INTO `typee` VALUES (5, '可爱'); + +-- ---------------------------- +-- Table structure for user +-- ---------------------------- +DROP TABLE IF EXISTS `user`; +CREATE TABLE `user` ( + `us_id` int(11) NOT NULL AUTO_INCREMENT, + `us_name` varchar(4) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, + `us_age` varchar(3) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `us_sex` varchar(1) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + PRIMARY KEY (`us_id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of user +-- ---------------------------- +INSERT INTO `user` VALUES (1, '迪迦', '11', '男'); +INSERT INTO `user` VALUES (2, '赛文', '34', '男'); +INSERT INTO `user` VALUES (3, '奥特之父', '33', '男'); +INSERT INTO `user` VALUES (4, '奥特曼', '22', '男'); + +SET FOREIGN_KEY_CHECKS = 1; + +``` +