Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the types of mysql constraints?

Shulou Source: shulou.com Published: 2022-06-03 07:09:59 11月15日 Update

This article mainly introduces what kinds of mysql constraints have, which have certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let Xiaobian take you to understand it together.

1, not null is not empty.

eg:user name varchar(40)not nuluser name This column cannot have null values.

2) Unique constraints.

The following data cannot be duplicated with the preceding;eg:cardNochar(18)unique; duplicate data is not allowed in the cardNo column.

Primary key constraint (non-empty + unique).

Usually used in the id column of a table. Tables basically have id columns, which are unique flags.

id int primary key auto_increment, id does not need to be maintained by ourselves.

When inserting data, null is inserted directly, and the filling is automatically increased to avoid duplication.

examples

CREATE TABLE student(id INT PRIMARY KEY AUTO_INCREMENT, --primary key self-increasing NAME VARCHAR(30) UNIQUE, --unique constraint gender CHAR(1) NOT NULL DEFAULT 'male'); Thank you for reading this article carefully, I hope Xiaobian shared "mysql constraints what kind of" This article is helpful to everyone, but also hope that everyone more support, pay attention to industry information channels, more relevant knowledge waiting for you to learn!

Tags: Articles data categories growth value interest at the same time examples more friends logos knowledge editing industry information information channels channels references learning help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info NVidia Apple OPPO Reno Shulou Information