[Database learning from scratch] 5. Database integrity

Physical integrity

Keywords: PRIMARY KEY The
main code has column level and table level.
The difference is that the column level is written at the same time as the column definition. For example, col1 char(2) primary key
and the table level is defined in the column. Write later, if col1, col2 have been defined, set them as primary key(col1,col2)


Referential integrity

Keywords: foreign key FOREIGN KEY
can be directly defined: foreign key(col2) references TableTest(col1);
it can also be written as a word with integrity constraints: constrant fk_col2 foreign key(col2) references Table_test(col1)


User-defined integrity

Keywords: CONSTRAINT, CHECK, NOT NULL, UNIQUE, FOREIGN KEY, etc.
Such as: set gender can only be male or female
alter table student
add constraint sex_check check(Ssex in('male','female'));


trigger

See mySQL trigger

Guess you like

Origin blog.csdn.net/weixin_44062380/article/details/106958494