MySQL Constraints
Constraints are the utilities that restrict the entry of data into the table if the specified condition is not fulfilled. They are primarily of the following type -- Primary key, foreign key, check, unique, not null
Primary Key : Primary key prevents duplicate entry. It is called row-based constraints(it means inside a table there is only one field can be declared primary ) No null Value can be entered.
Unique Key: It will not let enter a duplicate value in the field. But a Null Value can be entered. It is called a column-based constraint.
Foreign Key: A column is called a foreign key when it refers to the primary key column of another table.
Not NULL: It will not allow entering null Value in the field. But duplicate value can be entered.
MySQL Index:
indexing is basically of four types : => Primary => Unique => Index => full-text
Primary Key:
- Primary Key prevent duplicate entry.
- Only one field can be defined Primary
- it is row-based Constraint
Unique Key:
- Unique Key also prevents the duplicate entry.
- More than one field can be defined as unique
- it is column-based Constraint
Index and full-text:
Index and full-text both are used for filtration. when you need to search if you have to write the full name of field i.e. indexing. on the other hand, if the searching is based on the basis of characters it is full-text.
