mysqlan expression of a check
时间: 2023-09-02 07:09:33 浏览: 99
In MySQL, you can use the `CHECK` constraint to define a condition that must be satisfied before a row can be inserted or updated. The syntax for creating a `CHECK` constraint is as follows:
```
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
...
CONSTRAINT constraint_name CHECK (condition)
);
```
Here, `constraint_name` is the name of the constraint and `condition` is the condition that must be satisfied. For example, if you have a table for storing information about employees and you want to make sure that the salary is greater than or equal to 0, you can use the following `CHECK` constraint:
```
CREATE TABLE employees (
id INT PRIMARY KEY,
name VARCHAR(50),
salary DECIMAL(10, 2),
CONSTRAINT salary_check CHECK (salary >= 0)
);
```
This will ensure that any row inserted or updated in the `employees` table will have a salary that is greater than or equal to 0.
阅读全文