diff --git "a/\350\202\226\351\243\236\351\271\217/20240903/\346\225\260\346\215\256\345\272\223\350\204\232\346\234\254.sql" "b/\350\202\226\351\243\236\351\271\217/20240903/\346\225\260\346\215\256\345\272\223\350\204\232\346\234\254.sql" new file mode 100644 index 0000000000000000000000000000000000000000..6e84443c8f1a46f6ebc47a6e6eabf04cb78a2b83 --- /dev/null +++ "b/\350\202\226\351\243\236\351\271\217/20240903/\346\225\260\346\215\256\345\272\223\350\204\232\346\234\254.sql" @@ -0,0 +1,75 @@ +CREATE DATABASE movie; + +use movie; + /*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2024/9/4 9:11:47 */ +/*==============================================================*/ + + +drop table if exists info; + +drop table if exists type; + +drop table if exists viewer; + +/*==============================================================*/ +/* Table: info */ +/*==============================================================*/ +create table info +( + Mid int auto_increment not null, + Vid int, + Mname varchar(255), + Mactor varchar(255), + Mdirctor varchar(255), + Mtime int, + primary key (Mid) +); + +INSERT INTO info (Mid,Vid,Mname,Mactor,Mdirctor,Mtime) VALUES(1,1,'让子弹飞','姜文,葛优','姜文',132); + +/*==============================================================*/ +/* Table: type */ +/*==============================================================*/ +create table type +( + Tid int auto_increment not null, + Mid int not null, + Tname varchar(255), + primary key (Tid) +); + +INSERT INTO type (Tid,Mid,Tname) VALUES(1,1,'喜剧'); + +/*==============================================================*/ +/* Table: viewer */ +/*==============================================================*/ +create table viewer +( + Vid int auto_increment not null, + Tid int not null, + Vname varchar(255), + Vage int, + Vgender char(1), + primary key (Vid) +); + +INSERT into viewer (Vid,Tid,Vname,Vage,Vgender) VALUES(1,1,'卢比',18,'女'); + +alter table info add constraint FK_watch foreign key (Vid) + references viewer (Vid) on delete restrict on update restrict; + +alter table type add constraint FK_has foreign key (Mid) + references info (Mid) on delete restrict on update restrict; + +alter table viewer add constraint FK_like foreign key (Tid) + references type (Tid) on delete restrict on update restrict; + +SELECT *FROM info; +SELECT *FROM viewer; +SELECT *FROM type; + + + + \ No newline at end of file diff --git "a/\350\202\226\351\243\236\351\271\217/20240903/\346\225\260\346\215\256\345\272\223\350\256\276\350\256\241\350\257\276\345\240\202\347\254\224\350\256\260.md" "b/\350\202\226\351\243\236\351\271\217/20240903/\346\225\260\346\215\256\345\272\223\350\256\276\350\256\241\350\257\276\345\240\202\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..76604d822d42dc72e2e1066dca57f0c28825f1ae --- /dev/null +++ "b/\350\202\226\351\243\236\351\271\217/20240903/\346\225\260\346\215\256\345\272\223\350\256\276\350\256\241\350\257\276\345\240\202\347\254\224\350\256\260.md" @@ -0,0 +1,53 @@ +# 数据库设计课堂笔记 + +## 1. 数据库设计概述 +数据库设计是创建数据库的过程,包括确定数据需求、选择数据模型、定义数据结构和约束、以及优化性能。设计良好的数据库可以提高数据的一致性、减少冗余,并提高查询效率。 + +## 2. 数据库设计步骤 + +### 2.1 需求分析 +- **业务需求**:理解业务流程和数据使用场景。 +- **用户需求**:确定用户对数据的访问和操作需求。 + +### 2.2 概念设计 +- **实体识别**:识别业务中的对象,如客户、订单、产品等。 +- **关系定义**:确定实体之间的关系,如一对多、多对多。 + +### 2.3 逻辑设计 +- **E-R模型**:使用实体-关系模型来表示数据结构。 +- **规范化**:应用规范化理论(如三大范式)来优化设计。 + +### 2.4 物理设计 +- **存储结构**:确定数据在数据库中的存储方式。 +- **索引设计**:创建索引以提高查询性能。 + +### 2.5 实施与维护 +- **数据库创建**:在数据库管理系统中创建数据库和表。 +- **数据迁移**:将现有数据迁移到新数据库。 +- **性能监控**:监控数据库性能并进行必要的优化。 + +## 3. 数据模型 + +### 3.1 概念模型 +- **E-R图**:实体-关系图,用于表示实体及其关系。 + +### 3.2 逻辑模型 +- **关系模型**:使用表格、行和列来表示数据。 + +### 3.3 物理模型 +- **存储模型**:考虑数据的存储方式和访问方法。 + +## 4. 规范化理论 + +### 4.1 第一范式(1NF) +- 每个字段都是不可分割的基本数据项。 + +### 4.2 第二范式(2NF) +- 表必须有一个主键。 +- 非主键字段必须完全依赖于主键。 + +### 4.3 第三范式(3NF) +- 非主键字段之间不能相互依赖。 + +## 5. 总结 +数据库设计是一个迭代和持续的过程,需要不断地评估和优化以满足业务需求和性能目标。通过理解和应用数据库设计的原则和实践,可以创建出高效、可靠和可扩展的数据库系统。 \ No newline at end of file diff --git "a/\350\202\226\351\243\236\351\271\217/20240903/\346\250\241\345\236\213\346\210\252\345\233\276.doc" "b/\350\202\226\351\243\236\351\271\217/20240903/\346\250\241\345\236\213\346\210\252\345\233\276.doc" new file mode 100644 index 0000000000000000000000000000000000000000..36fb63af3343a1968461d96d8b2ff94304f9076f Binary files /dev/null and "b/\350\202\226\351\243\236\351\271\217/20240903/\346\250\241\345\236\213\346\210\252\345\233\276.doc" differ