Software Designer (Database)

database

  • Three-level mode two-level image

    • External mode (submode of user mode) = "view, conceptual mode (mode) = "basic table, internal mode (storage mode) = "storage file
    • External schema/schema image (logical independence), schema/internal schema image (physical independence)
  • relational schema

    • Tuple (row) a record, attribute (column) the first row is the attribute name, followed by the attribute value (data item)
    • Candidate code (candidate key) can uniquely identify a tuple
    • Primary key (primary key) candidate key, select one as the primary key (sometimes the primary key is equal to the candidate key)
    • Main attribute: the attribute included in the candidate code, not included as a non-main attribute
    • Outer key: not the primary key in this relationship, but the primary key in another relationship
    • Full code: All attribute components are candidate codes for this relational model
    • Super code: add an attribute as a candidate code on the basis of the original candidate code
    • The relational model consists of a relational data structure, a collection of relational operations, and relational integrity constraints
      • Integrity constraints
        • Entity Integrity = "The value of the main attribute cannot be empty or partially empty
        • referential integrity
          • The outer key x of relation 1 must correspond to the primary key of relation 2, and the value of the outer key x must be found in relation 1, or be empty
        • User Defined Integrity
  • Relational Algebra Operators

    • Set operator: union intersection (1-2 belongs to 1 but not 2) Cartesian product
    • Specialized relational operators: SELECT (get out satisfied rows) PROJECT (get out columns) JOIN DIVIDE
      • Cartesian product must first be used to filter the theat connection equivalent connection (symbol =)
      • natural connection
        • After the first Cartesian product, select the columns with common attributes. When the columns are all equal, then remove the columns in one of the relationships, and the rest is
        • Left (right) outer join, natural join first, then save the left (right) record, if there is no one, it will be null
        • Full outer join, first natural join and then left and right join
      • Turn to SQL statement
        • Projection is select xx from xx
        • The choice is where xxx
        • Cartesian product select xxx from R,S
        • Natural connection select xxx from R,S where xx and xx kill the same column
  • SQL

    • Classification of SQL language
      • DDL Data Definition Language
        • create create alter modify drop delete
      • DML Data Manipulation Language
        • insert into S values xxx、delete from S、update S set xxx
      • DQL data query language
        • distinct removes duplicate columns as gives the column an ​​alias and the alias of the table following the column is taken directly
        • Between x and x choose one of where x in (xxx) between xx
        • (not) like fuzzy query %arbitrary length_single character
        • order by xxx desc descending default ascending asc needs to be the last statement
        • aggregate function
          • avg average sum sum max max min min
          • count(*) empty rows are not counted
          • group by group having conditional grouping after grouping should appear after select
          • Equivalent connection select * from S where Sx=Cx
          • left and right join from C left join S on condition
          • inner join outer join
          • Subquery where exists (select xxx)
          • Union and intersect intersect except difference to the operation of the query structure
      • DCL Data Control Language
      • Authorize grant permission (insert) on table S to user
      • with grant option
      • Remove remove permission on table user (public all)
  • view

    • A view is a table derived from one or more basic tables or views, and is a virtual table
    • Create create view view name as select xxx
    • Finally, if you add this sentence with check option, the view is update insert delete. When defining the view, you must abide by all the conditions after where when defining the view.
  • Create indexes that change the internal schema of the database

  • relational schema

    • X->YY depends on X If Y does not contain X, then it is a non-trivial dependency (normal) If it does, it is trivial
    • X–f–>YY The complete functional dependence of the subsets in X cannot be independently derived from Y, and one push must be complete
    • X–p–YY partial (local) function depends on the subset in X to deduce Y
    • X->Y Y->Z get X->Z transfer function dependency
  • The closure looks for only the characters on the left to see if U can be released, if not, add characters both on the left and right until U is released

  • Paradigm

    • First normal form: each atomic item is an indivisible data item
      • Problems such as data redundancy and update exceptions (insertion and deletion) cannot be ruled out, and there may be partial functional dependencies
    • The second normal form (after the first decomposition): It satisfies the first normal form, and each non-main attribute is completely functionally dependent on the candidate key (eliminating the partial dependence of the non-main attribute on the candidate key)
      • Problems such as data redundancy and update exceptions (insertion and deletion) cannot be ruled out, and there may be functional transitive dependencies
    • The third normal form (the second continues to decompose): satisfy the second normal form, and each non-primary attribute is non-transfer function dependent on the candidate code (eliminate the transitive dependence of the non-primary attribute on the candidate code)
      • There may be partial functional dependence and transitive dependence of the main attribute on the code (elimination is BCNF)
    • The fourth normal form: X->->Y multi-valued dependency. X contains a candidate code of R, which is the fourth normal form
      • Eliminate non-trivial and non-functional dependencies for multi-valued dependencies
  • Database Design

    • six steps
      • User needs analysis (understand user needs to determine system boundaries)
        • As a basis for conceptual structure design, establish requirements specification documents, data dictionaries, and data flow diagrams
      • Conceptual Design (ER Diagram)
        • Composite attribute ps: address can be divided into provinces, cities and counties and cannot be further divided, it is a simple attribute
        • Multi-valued attribute ps: An attribute corresponds to a set of value relatives, and multiple one-to-one is a single-valued attribute
        • Null attribute, no value or unknown is null, meaning meaningless or unknown
        • Derived attribute ps: years of age obtained through other attribute operations Age = this year - date of birth
        • Select partial application: design partial view = "merge cancel conflict =" modify reconstruction to eliminate redundancy
          • Types of merge conflicts: attribute conflicts (different ER diagrams exist for the same attribute), naming conflicts (attributes with the same meaning have different names on different ER diagrams, or attributes with the same name represent different meanings), structural conflicts (The same entity has different attributes in different ER diagrams, here the entity is the attribute over there)
      • Logical design (relational schema, relational normalization)
        • Convert ER diagrams to specified data models, identify integrity constraints, and identify user views
      • Physical design, database implementation phase, database operation and maintenance phase
      • ER diagram to relational schema
        • When 1-1, the first type: the connection becomes an independent mode, adding the attribute of the connection, and the codes of the two entities, and the primary key is the code of any entity. The second is to add the code and connection attributes of one entity to the entity of the other.
        • When it is 1-n, the first type: the connection becomes an independent mode, adding the attribute of the connection, and the codes of the two entities, and the ma on the m side is the code of the entity. The second is to add the code and connection attributes of one entity to multiple entities.
        • At the time of mn, the connection becomes an independent mode, and the attribute of the connection is added, together with the codes of the two entities, and the ma on both sides constitute the code of the entity.
  • affairs

    • Atomicity (either do all or nothing), consistency (one consistent state becomes another consistent state), isolation (mutual isolation, multiple transaction execution, invisible to other transactions), persistence (The transaction is successfully submitted, and it is also permanently valid for database operations)
  • blockade

    • Exclusive locks (X locks or write locks), after adding X locks, you cannot add other locks, nor X, readable and modifiable
    • Shared lock (S lock or read lock), S lock can also be added after adding S lock, read-only cannot be modified
  • Distributed database
    Please add a picture description

Guess you like

Origin blog.csdn.net/weixin_45113182/article/details/128679144