search
HomeDatabaseMysql Tutorial笔试面试那件小事(数据库-范式)

笔试面试那件小事(数据库-范式)

Jun 07, 2016 pm 04:01 PM
datadatabaseconceptRelatedKnowledgewritten examinationparadigminterview

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(学号,姓名,年龄,性别,系别,系办公地址,系办电话),单一码为学号。并且系办地址和系办电话依赖于系别。存在传递函数依赖。

将学生表拆成两个表:

学生(学号,姓名,年龄,性别,系别)

系别(系别,系办地址,系办电话)

上述关系满足三范式。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Explain the InnoDB Buffer Pool and its importance for performance.Explain the InnoDB Buffer Pool and its importance for performance.Apr 19, 2025 am 12:24 AM

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL vs. Other Programming Languages: A ComparisonMySQL vs. Other Programming Languages: A ComparisonApr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Learning MySQL: A Step-by-Step Guide for New UsersLearning MySQL: A Step-by-Step Guide for New UsersApr 19, 2025 am 12:19 AM

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL: Essential Skills for Beginners to MasterMySQL: Essential Skills for Beginners to MasterApr 18, 2025 am 12:24 AM

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL: Structured Data and Relational DatabasesMySQL: Structured Data and Relational DatabasesApr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL: Key Features and Capabilities ExplainedMySQL: Key Features and Capabilities ExplainedApr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

The Purpose of SQL: Interacting with MySQL DatabasesThe Purpose of SQL: Interacting with MySQL DatabasesApr 18, 2025 am 12:12 AM

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

MySQL for Beginners: Getting Started with Database ManagementMySQL for Beginners: Getting Started with Database ManagementApr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools