chapter-2 basic knowledge of database

The following courses are derived from MOOC learning—see the original course: Database Principles and Applications
Postgraduate Review

Foreword:

abstraction and model

1. Use different models to describe objects in different abstraction levels of data

Person’s name, gender—>conceptual model——>data model supported by DBMS——>physical model

2. Conceptual Modeling: Modeling information from the user's point of view

​ Can be described by the entity relationship model ER diagram

3. Data model:

  • Logical Data Model: Provides a way to represent and organize data
  • Physical data model: the abstraction of the lowest-level data; describing the representation and storage methods of data in the system

image-20210115153543659

conceptual model

  1. entity

Things that show the objective existence of the world and can be distinguished from each other are processed and abstracted into entities of the information world;

The basic unit of the information world; can be concrete or abstract; needs to be named

  1. Attributes: The characteristics of things in the real world are reflected in their corresponding entities; an entity can have several attributes
  2. Entity type: a collection of attribute names to abstract and describe similar entities [student (student number, name)]
  3. Entity set: A collection of entities of the same type with the same set of attributes

The conceptual model is the first layer of abstraction in the real world. The conceptual model commonly used in database technology is (entity-relationship model)

image-20210115154002565

Keywords of ER Diagram

  • Attributes
  • Keyword: the minimum set of attributes that uniquely identify an entity
  • Contact: Form [intra-entity set and inter-set] arity [unary 1-1 binary 1-n multivariate mn]

image-20210115154223723

Supplement: IS-A Contact

There is an IS-A relationship between entity A and entity B, and entity B inherits all attributes in A and the relationship related to A through the IS-A relationship, and has its own unique attributes

image-20210115154443021

Supplement: Weak entity: the existence of an entity depends on other entities (regular or strong entities), known as weak entities

For example, family members depend on students; family members are weak entities (represented by double-line rectangles and double diamonds)

data model

Strictly define a collection of concepts— accurately describe the static properties, dynamic properties, and integrity constraints of the system

Component elements: data structure + data operation + integrity constraints

Data structure: describe the database schema [describe a collection of object types]

Data manipulation: the notation of the operation, its exact meaning, the rules of operation and the language of implementation must be defined

Integrity constraints: basic general principles that must be met to ensure the correctness, validity, and compatibility of data

Evolution of the database model

The evolution process is a main line of database technology development

hierarchical model

Based on the tree structure , organized according to the structure of the ordered tree, it can only represent 1:N relationship

mesh model

Adopt network structure , describe M:N ; programming is complex; represent DBTG system

Relational Model [Broad]

Proposed in 1970, the ACM Turing Award is based on the concept of "relationship" in set theory; operations are set operations

Single data structure —relationships can represent entities or describe relationships between entities

As long as a single relationship structure can be used to represent the relationship between entities and entities

semi-structured data model

image-20210115230832280

image-20210115230920781

object-oriented model

The basic concepts are objects and classes

Any entity in the real world is an object

  • An object can contain multiple properties
  • Objects can contain several methods
  • Objects are encapsulated
  • Communication between objects is achieved through message passing

All objects that share the same set of properties and method sets are combined to form an object class (class), and an object is an instance of a certain class

  • Classes can have nested structures, inheriting all properties and methods directly and indirectly from ancestors

Over: Object Relational Model

The difference between relations, relational schemas, and relational models

  1. Relationship: A relationship corresponds to a table that is usually said

  2. Relational Schema: Description of Relationships

  3. Relational model: The relational model consists of three parts : relational data structure, relational operation set, and relational integrity constraints .

  4. The Difference Between Relationships and Relational Schemas

    • A relational schema is a type, a relation is a value, and a relational schema is a description of a relation

    • A relationship is the state or content of a relationship schema at a certain moment, and the relationship schema is static and stable.

    • Relationships are dynamic and change over time, because relational operations are constantly updating the data in the database

    • Similar to the difference between "class" and "object" in object-oriented programming. "relationship" is an instance of "relational schema",

    You can understand "relationship" as a table with data, and "relational schema" is the table structure of this data table. **

  5. The difference between a relational model and a relationship

    • A relational model contains relations, and a relation is the data structure of a relational model. In a relational model,
    • Entities in the real world and all levels of connections between entities are represented by a single type of structure, the relationship

Search for articles on the Internet to supplement the above: the difference between the three

Why is mySQL called the "relational" model?

definition of relationship

The data model adopted by a relational database is a relational model - the reverse may be more appropriate,

That is, the database adopts a relational model, so it is called a relational database.

​ So, what does the "relationship" mentioned here refer to? If you think about it deeply, you will find that this word is actually very abstract, not easy to understand, and it is easy to be confused with the "relationship" in words such as "interpersonal relationship" and "relationship tension" that we use in our daily life. That being the case, wouldn't it be okay to call it a "table" model without using abstract words like "relationship" from the beginning? The so-called relationship, after all, isn’t it still a two-dimensional table? Reasonable questions like this have been raised many times since the birth of the relational model. "What do you mean by always talking about relationship, relationship?"

Difference between relation and table:

  1. Duplicate tuples are not allowed in relations , but can exist in tables. That is, a relationship is a set that generally does not allow duplicate elements, and a table is a multiple set

  2. The tuples in a relation do not have a top-down order , while the rows in a table have a top-down order

  3. Attributes in a relationship do not have a left-to-right order , while columns in a table have a left-to-right order

  4. The values ​​of all the attributes in the relationship are indivisible , while the values ​​of the columns in the table are divisible. In other words, the attributes in the relation satisfy the first normal form, but the columns in the table do not satisfy the first normal form

It can be seen from these few columns that there is still a big difference between a relationship and a table. Compared with relationships, tables are less rigorously defined and less clear. In the previous article, we used the words "tuple" and "attribute" many times. Do you think "tuple ≈ row" and "attribute ≈ column"?

img

​ In actual work, it is not particularly beneficial to call "columns" "attributes" and "number of rows" "potentials".

​ The relational model is based on the set theory in mathematics, so some terms of set theory are used, and we can understand this. However, when reading some theoretically rigorous books, you may find that the author is used to using "attributes" instead of "columns" and "tuples" instead of "rows", so it is good to know their correspondence.

The definition of the relationship can be given by a formula like the following. R ⊆ (D1×D2×D3 ··· ×Dn)

(The relationship is represented by the symbol R, the attribute is represented by the symbol Ai, and the domain of the attribute is represented by the symbol Di)

This formula reads "The relation R is a subset of the Cartesian product of the domains D1, D2, ..., Dn".

, use "tuples" instead of "rows", so it is still beneficial to know their correspondence.

The definition of the relationship can be given by a formula like the following. R ⊆ (D1×D2×D3 ··· ×Dn)

(The relationship is represented by the symbol R, the attribute is represented by the symbol Ai, and the domain of the attribute is represented by the symbol Di)

This formula reads "The relation R is a subset of the Cartesian product of the domains D1, D2, ..., Dn".

In fact, the Cartesian product refers to " the set with the largest number of combinations generated using the domain of each attribute".

Guess you like

Origin blog.csdn.net/qq_38758371/article/details/130093982