Revisit "Introduction to Database System" [First Basics] [Chapter 5 Database Integrity]

The content of this article is the review notes of the self-study course "Introduction to Database System" by Professor Wang Shan and Sa Shixuan of Renmin University of China. The learning video comes from Xiaopo Station ( portal ), corresponding to video P32-P36, which belongs to the textbook "[First Basics]" "[Chapter 5 Database Integrity]" content.


Insert picture description here


P32 database integrity overview and entity integrity

32.1 Integrity of the database

  • The correctness of the data (the data must conform to the actual situation)
  • Data compatibility (data in different relational tables for the same object is logical)

32.2 Physical integrity

  • Definition code eg1:
    Define the Sno attribute in the Student table as a code
    Insert picture description here
    eg2: Define the Sno, Cn oh attribute group in the SC table as a code
    Insert picture description here
  • Entity integrity check and default handling
    ① Check whether the master code value is unique, if not, refuse to insert or modify it
    ② Check whether each attribute of the master code is empty, and refuse to insert or modify as long as one of them is empty
    Insert picture description here
    Insert picture description here

P33 Referential integrity

33.1 Referential integrity definition

Insert picture description here

33.2 Referential integrity check and default handling


P34 User-defined integrity

34.1 Constraints on attributes

  • Column value is not empty (NOT NULL)
    Insert picture description here
  • Unique column value (UNIQUE)
    Insert picture description here
  • Check whether the column value meets a conditional expression (CHECK phrase)
    Insert picture description here

34.2 Constraints on Tuples

Insert picture description here

34.3 Summary and Comparison of Database Integrity

Insert picture description here


P35 Integrity Constraint Naming Clauses and Assertions

35.1 Integrity Constraint Naming Clause

  • Example eg: integrity constraint naming clause
    Insert picture description here
  • Example eg: modify the integrity restriction in the table
    Insert picture description here

35.2 Affirmation

  • Statement format for creating assertion
CREATE ASSERTION <断言名> <CHECK 子句>
  • Example eg:
    Insert picture description here
  • Statement format for delete assertion
DROP ASSERTION <断言名>;

P36 trigger

36.1 Trigger

  • A special event-driven process defined by the user on the relational table ;
  • Any user's addition, deletion or modification of the table will be automatically activated by the server to the corresponding trigger
  • Triggers can try more complex inspections and operations, with more surprises and more powerful data control capabilities

36.2 Trigger operation

  • Define triggers (can only be defined on the basic table )
    Insert picture description here
    Insert picture description here
  • Activation trigger
    Insert picture description here
  • Delete trigger
    Insert picture description here

notes

Insert picture description here


Guess you like

Origin blog.csdn.net/weixin_44421798/article/details/112612556