Table of Contents
一、关系数据结构及形式化定义
1、关系模式的数据结构
2、形式化定义
二、关系操作
三、关系的完整性
1、实体完整性
2、参照完整性
3、用户定义完整性
Home Database Mysql Tutorial 数据库基础<二)关系数据库

数据库基础<二)关系数据库

Jun 07, 2016 pm 03:22 PM
amp relation Base definition database data structure mold

一、关系数据结构及形式化定义 1、关系模式的数据结构 关系模式的数据结构非常简单,只包含单一的数据结构:关系 2、形式化定义 域:一组具有相同数据类型的值的集合 笛卡尔积 关系 候选码:若关系中的某一属性组能唯一地标识一个元组,则称该属性组为候选码

一、关系数据结构及形式化定义

1、关系模式的数据结构

关系模式的数据结构非常简单,只包含单一的数据结构:关系

2、形式化定义

域:一组具有相同数据类型的值的集合

笛卡尔积

关系

候选码:若关系中的某一属性组能唯一地标识一个元组,则称该属性组为候选码

主码:若一个关系有多个候选码,则选定其中一个为主码

候选码的诸属性成为主属性,不包含在任何候选码中的属性称为非主属性或非码属性

全码:关系模式的所有属性是这个关系模式的候选码,称为全码

关系类型:基本关系(基本表/基表)、查询表、视图表

二、关系操作

\

连接:

等值连接:在笛卡尔积中选取两属性值相等的那些元组。

自然连接:等值连接的基础上,去掉重复的属性列

外连接:把舍弃的元组也保存在结果中,而在其他属性上填空值。如果只把左(右)边关系中要舍弃的元组保留就叫做左(右)外连接。

具体实例:

\

 

三、关系的完整性

1、实体完整性

实体完整性规则:若属性(指一个或一组属性)A 是基本关系 R 的主属性,则 A 不能取空值

2、参照完整性

外码:设 F 是基本关系 R 的一个或一组属性,但不是关系 R 的码。 Ks 是基本关系 S 的主码。 如果 F 与 Ks 相对应,则称 F 是 R 的外码。如下图:

\

实例:学生(学号,姓名,性别,专业号)

专业(专业号,学分,授课老师)

上面的学生关系的”专业号“属性与专业关系的主码”专业号“相对应,因此”专业号“属性是学生关系的外码

参照完整性规则:若属性(或属性组)F 是基本关系 R 的外码,它与基本关系 S 的主码 K 相对应(基本关系 R 和 S 不一定是不同的关系),

则对于 R 中每个元组在 F 上的值必须为:

或者取空值(F 的每个属性值均为空值);

或者等于 S 中某个元组的主码值。

实例:如上面的例子中,学生关系中每个元组的”专业号“属性只能取下面两类值:

空值:表示尚未给该学生分配专业

非空值:这时该值必须是专业关系中元组”专业号“的值,表示该学生不可能分配到一个不存在的专业中。

即被参照关系”专业“中一定存在一个元组,它的主码值等于该参照关系”学生“中的外码值。

3、用户定义完整性

用户定义完整性就是针对某一具体关系数据库的约束条件。它反映某一具体应用所涉及的数据必须满足的语义要求。

例如某个属性必须取唯一值、某个非主属性也不能取空值等等。

Statement of this Website
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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

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())

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

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

Java data structures and algorithms: in-depth explanation Java data structures and algorithms: in-depth explanation May 08, 2024 pm 10:12 PM

Data structures and algorithms are the basis of Java development. This article deeply explores the key data structures (such as arrays, linked lists, trees, etc.) and algorithms (such as sorting, search, graph algorithms, etc.) in Java. These structures are illustrated through practical examples, including using arrays to store scores, linked lists to manage shopping lists, stacks to implement recursion, queues to synchronize threads, and trees and hash tables for fast search and authentication. Understanding these concepts allows you to write efficient and maintainable Java code.

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

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.

How does Go WebSocket integrate with databases? How does Go WebSocket integrate with databases? Jun 05, 2024 pm 03:18 PM

How to integrate GoWebSocket with a database: Set up a database connection: Use the database/sql package to connect to the database. Store WebSocket messages to the database: Use the INSERT statement to insert the message into the database. Retrieve WebSocket messages from the database: Use the SELECT statement to retrieve messages from the database.

PHP data structure: The balance of AVL trees, maintaining an efficient and orderly data structure PHP data structure: The balance of AVL trees, maintaining an efficient and orderly data structure Jun 03, 2024 am 09:58 AM

AVL tree is a balanced binary search tree that ensures fast and efficient data operations. To achieve balance, it performs left- and right-turn operations, adjusting subtrees that violate balance. AVL trees utilize height balancing to ensure that the height of the tree is always small relative to the number of nodes, thereby achieving logarithmic time complexity (O(logn)) search operations and maintaining the efficiency of the data structure even on large data sets.

How to use database callback functions in Golang? How to use database callback functions in Golang? Jun 03, 2024 pm 02:20 PM

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

How to handle database connections and operations using C++? How to handle database connections and operations using C++? Jun 01, 2024 pm 07:24 PM

Use the DataAccessObjects (DAO) library in C++ to connect and operate the database, including establishing database connections, executing SQL queries, inserting new records and updating existing records. The specific steps are: 1. Include necessary library statements; 2. Open the database file; 3. Create a Recordset object to execute SQL queries or manipulate data; 4. Traverse the results or update records according to specific needs.

See all articles