Home  >  Article  >  Backend Development  >  Learn what constraints are in PHP in one minute? There are mainly the following types of constraints?

Learn what constraints are in PHP in one minute? There are mainly the following types of constraints?

慕斯
慕斯Original
2021-06-25 18:02:501450browse

We have learned so much about PHP in PHP. I don’t know how much you know about constraints. I believe that a large number of people will not know this part of the knowledge. So don’t worry, this article will lead you to a more profound understanding. to learn about this content.

Related recommendations: What is the enum type in PHP? set type?

Constraints

What are constraints?

Yuedong is to ask what the data needs to meet A kind of "regulation" of conditions

There are mainly the following types of covenants:

Primary key covenants: Format: primarykey(field name);

Meaning (function), so that the value of this setting field can be used to "uniquely determine a row of data", which actually means "primary key".

Unique key form, unique key(field name);

Meaning (function) 1 Make the value of the set field "unique", naturally it is also distinguishable.

Foreign key constraints, form:

foreign key(字段名) references

Other table names (corresponding to field names in other tables);

Meaning (function): use The value of this set field must already exist in the corresponding field in the corresponding table specified by the other party.

Non-null constraint, in the form :

 not null,

In fact, it is the "not nul!" attribute written when setting a field.

Default constraints: Form:

 default XX 值:

In fact, it is the "default default value" attribute written when setting a field

In fact, Feng key About East, unique constraints and foreign key constraints are just "two different ways of saying the same thing". They are also called "primary key index", "unique index" and "foreign key index".

Check the East: Format:

check (某种判断语句),

For example,

create table tab1 (
age tinyint,
check (age>=0 andage <100) /* 这就是检查约束*/
<?php
//演示外键索引: 
 create table banji(
  id int auto increment primary key,
  banjihao varchar(10) unique key comment &#39;班级号&#39;,
  banzhuren varchar(10) comment &#39;班主任&#39;,
  oper_date date comment &#39;开班日期&#39;
  );
  create table xuesheng (
  stu_ id int auto increment primary key,
  name varchar(10),
  age tinyint,
  banji id int comment &#39; 班级id&#39; ,
  foreign key (banji_id) references banji(id)
  );

Related learning video sharing: php video tutorial

The above is the detailed content of Learn what constraints are in PHP in one minute? There are mainly the following types of constraints?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn