笔试面试那件小事(数据库-范式)
1相关概念和知识 数据依赖:反映一个关系内部属性与属性之间的约束关系,是现实世界属性相互联系的抽象,属于数据内在的性质和语义的体现 规范化理论:是用来设计良好的关系模式的基
1>相关概念和知识
数据依赖:反映一个关系内部属性与属性之间的约束关系,是现实世界属性相互联系的抽象,属于数据内在的性质和语义的体现
规范化理论:是用来设计良好的关系模式的基础。它通过分解关系模式来消除其中不合适的数据依赖,以解决插入异常、删除异常、更新异常和数据冗余问题
函数依赖:简单的说,对于关系模式的两个属性子集X和Y,若X的任一取值都能唯一确定Y的值,那么则称Y函数依赖于X,记为X->Y
非平凡函数依赖:对于关系模式的两个属性子集X和Y,如果X->Y,但是Y不是X的子集,那么就称X->Y为非平凡函数依赖
完全函数依赖:对于关系模式的两个属性子集X和Y,如果X->Y,并对于X的任何一个真子集X',都有X‘->Y,称为完全函数依赖
范式:指符合某一种级别的关系的集合。
1NF:若关系模式的所有属性都是不可分的基本数据项,则该关系属于1NF
2NF:1NF关系模式如果同时满足每一个非主属性完全依赖于码,则该关系模式为2NF
3NF:若关系模式的每一个非主属性,既不部分依赖于码,也不传递依赖于码,则该关系模式为3NF
BCNF:若一个关系模式的每个决定因素都包含码,则该关系模式为BCNF
数据库设计:是指对于一个给定的应该环境,构造优化的数据逻辑模式和物理结构,并据此建立数据库及其应用系统,使之能够有效的存储和管理数据,满足各种用户的应用需求,包括信息管理需求和数据库操作需求。
数据库设计的6个基本步骤:需求分析、概念结构设计、逻辑结构设计、物理结构设计、数据库实现、数据库运行和维护
概念结构设计:是指需求分析得到的用户需求抽象为信息结构。代表E-R图构建
逻辑结构设计:将概念结构模型(E-R图),转化为某个DBMS系统支持的数据模式。代码E-R转为关系数据模式
物理结构设计:为一个给定的逻辑数据模型选取一个合适应用环境的物理结构过程。包括设计数据的存储结构与存钱方法
抽象:指对实际的人、物、事和概念进行人为处理,抽取所关心的共同特征,忽略非本质的细节。
数据库设计必须遵循相结合的原则
数据字典主要包括数据项、数据结构、数据流、数据存储和处理过程5个部分
三种常见抽象方法:分类、聚集和概括
局部E-R图之间的冲突主要表现在属性冲突、命名冲突和结构冲突三个方面
数据库常用的存取方法:索引方法、聚簇方法和HASH方法
确定数据存放位置和存储结构需要考虑的因素主要有:存取时间、空间利用率和维护代价
&&&&&&&&&&&&数据库的范式&&&&&&&&&&&&&
1>第一范式(1NF)无重复的列
第一范式(1NF)中数据库表的每一列都是不可分割的基本数据项
同一列中不能有多值
即实体中的某一属性不能有多个值或者不能有重复的属性。不满足1NF的数据库不是关系数据库
2>第二范式(2NF)属性完全依赖于主键(消除部分函数依赖)
满足第二范式必须先满足第1范式
第二范式要求数据库表中的每一个实例或者元组必须可以被唯一的区分
3>第三范式(3NF)消除传递依赖
例子:在设计数据库表结构之前,我们先确定一下要设计的内容包含哪些。学号、学生姓名、年龄、课程、课程学分、系别、学科成绩、系办公地址、系办电话等信息。为了更好的理解信息,将上述信息分为以下几个方面:
学生信息包括哪些
学生选了哪些课,成绩是什么
每个课程的学分是多少
学生属于哪个系,系的基本信息是什么
首先第一范式(1NF):数据库表中的字段都是单一属性,不可再分。这个单一属性由基本类型构成,包括整数、字符、逻辑型、日期型等。目前在任何的关系数据库中不允许将一列分成多列,因此做出的数据库都符合第一范式的数据库
考虑第2范式,先把所有的信息放到一个表中(学号,学生姓名,年龄,性别,课程,课程学分,系别,学科成绩,系办地址,系办电话)并且存在下列的依赖关系。
1)(学号)->(姓名,年龄,性别,系别,系办地址,系办电话)
2)(课程名称)->(学分)
3)(学号,课程)->(学科成绩)
根据依赖关系我们生成三个表:
学生:student(学号,姓名,年龄,性别,系别,系办地址,系办电话)
课程:Course(课程名称,学分)
选课关系:selectCourse(学号,课程名称,成绩)
对照第二范式的要求,上述表已经满足第二范式。如果一个数据库不满足第2范式,则会产生:
数据冗余,更新异常,删除异常等;例如同一课程由n个学生选修,那么学分就重复了n-1次,同一个学生选修了m个课程,那么他的名字就重复多次
若调整了某一门课程的学分,则所有的学分都得更新,否则会出现一门课程多种学分的情况。假设一批学生已经选修完了课程,要将这些记录从数据库中删除,那么会连同课程的信息被一道删除。
接下来再考虑将数据库改成满足第3范式的数据库表:
看上面的学生表Student(学号,姓名,年龄,性别,系别,系办公地址,系办电话),单一码为学号。并且系办地址和系办电话依赖于系别。存在传递函数依赖。
将学生表拆成两个表:
学生(学号,姓名,年龄,性别,系别)
系别(系别,系办地址,系办电话)
上述关系满足三范式。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Facing lag, slow mobile data connection on iPhone? Typically, the strength of cellular internet on your phone depends on several factors such as region, cellular network type, roaming type, etc. There are some things you can do to get a faster, more reliable cellular Internet connection. Fix 1 – Force Restart iPhone Sometimes, force restarting your device just resets a lot of things, including the cellular connection. Step 1 – Just press the volume up key once and release. Next, press the Volume Down key and release it again. Step 2 – The next part of the process is to hold the button on the right side. Let the iPhone finish restarting. Enable cellular data and check network speed. Check again Fix 2 – Change data mode While 5G offers better network speeds, it works better when the signal is weaker

The latest video of Tesla's robot Optimus is released, and it can already work in the factory. At normal speed, it sorts batteries (Tesla's 4680 batteries) like this: The official also released what it looks like at 20x speed - on a small "workstation", picking and picking and picking: This time it is released One of the highlights of the video is that Optimus completes this work in the factory, completely autonomously, without human intervention throughout the process. And from the perspective of Optimus, it can also pick up and place the crooked battery, focusing on automatic error correction: Regarding Optimus's hand, NVIDIA scientist Jim Fan gave a high evaluation: Optimus's hand is the world's five-fingered robot. One of the most dexterous. Its hands are not only tactile

Recently, the military circle has been overwhelmed by the news: US military fighter jets can now complete fully automatic air combat using AI. Yes, just recently, the US military’s AI fighter jet was made public for the first time and the mystery was unveiled. The full name of this fighter is the Variable Stability Simulator Test Aircraft (VISTA). It was personally flown by the Secretary of the US Air Force to simulate a one-on-one air battle. On May 2, U.S. Air Force Secretary Frank Kendall took off in an X-62AVISTA at Edwards Air Force Base. Note that during the one-hour flight, all flight actions were completed autonomously by AI! Kendall said - "For the past few decades, we have been thinking about the unlimited potential of autonomous air-to-air combat, but it has always seemed out of reach." However now,

Last week, amid the internal wave of resignations and external criticism, OpenAI was plagued by internal and external troubles: - The infringement of the widow sister sparked global heated discussions - Employees signing "overlord clauses" were exposed one after another - Netizens listed Ultraman's "seven deadly sins" Rumors refuting: According to leaked information and documents obtained by Vox, OpenAI’s senior leadership, including Altman, was well aware of these equity recovery provisions and signed off on them. In addition, there is a serious and urgent issue facing OpenAI - AI safety. The recent departures of five security-related employees, including two of its most prominent employees, and the dissolution of the "Super Alignment" team have once again put OpenAI's security issues in the spotlight. Fortune magazine reported that OpenA

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

Llama3, the majestic king of open source, the original context window is only... 8k, which makes me swallow back the words "it smells so good". Today, when 32k is the starting point and 100k is common, is this intentional to leave room for contributions to the open source community? The open source community certainly didn't miss this opportunity: now with just 58 lines of code, any fine-tuned version of Llama370b can automatically scale to 1048k (one million) contexts. Behind the scenes is a LoRA, extracted from a fine-tuned version of Llama370BInstruct that extends good context, and the file is only 800mb. Next, using Mergekit, you can run it with other models of the same architecture or merge it directly into the model. 1048k context used
