Whether you are using SQL Server or MySQL, they are all relational databases. Since they are relational databases, you must comply with the "integrity rules of relational databases"
Apsaradb provides three types of integrity rules: entity integrity rules and custom completion rules based on integrity rules; among the three types of completion rules, the entity integrity rules and the reference integrity rules are the constraints of the integrity that the relational model must meet. They are called the relationship integrity rules. 1. entity integrity rules
Entity integrity rules refer to the primary attributes of a link (that is, some fields of the primary key, and the components of the primary key). They cannot be null. We know that every entity in real life is unique, even two computers with the same touch will have corresponding production dates to express their uniqueness. In reality, entities can be distinguished and they have a unique identifier, the primary key is used as the unique identifier in the corresponding relational model. The attribute in the primary key is that the primary attribute cannot be a null value ("unknown" or "meaningless"). If the primary attribute is null, it indicates that there are unidentifiable entities, that is, there are unidentifiable entities, which are in conflict with the real environment. Therefore, this entity must not be a complete entity. You may think this dogma is boring, even some do not understand, so it is easy to understand: when we design a table, don't each record have its own ID before it, and each ID is different, it is actually to distinguish between different records. Although the values of other fields are the same, as long as the IDs are different, two different records are separated, the Object Integrity rules are met. 2. The reference integrity rules indicate that if the foreign key R1 of The Link matches the primary key of The Link R2, therefore, each foreign key value must be found in the primary key value of The Link R2;
In fact, in two associated data tables, the foreign Key of a data table must be found in the Primary Key of another data table; let's take a look at the figure first. Let's look at figure 1 and figure 2 first. One is the Role table and the other is the User table ), you will find that the value of Role_ID for each field in the User table can be found in the Role_ID field of the Role table, right? See figure 3, the value of Role_ID In the last record in Figure 3 is "7" and cannot be found in Role_ID in the Role table in Figure 1. Therefore, figure 3 does not comply with the integrity rules of reference;
(Figure 1) (figure 2)
(Figure 3)
3. Custom integrity rules refer to the constraints of a specific actual database, which are determined by the application environment, reflects the requirements that must be met by the data involved in a specific application (for example, a person's age must be greater than zero), a user-defined integrity defined by the user according to a real situation in real life; for example, if you have an age field when designing a table, the value in this field cannot be less than 0, not more than 150, and no one is still 150 years old, right.