You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The CHECK constraint is used to limit the value range that can be placed in a column.
If you define a CHECK constraint on a column it will allow only certain values for this column.
If you define a CHECK constraint on a table it can limit the values in certain columns based on values in other columns in the row.
Example
CREATETABLEpersons (
name VARCHAR(40),
age INTEGERCHECK (age >=18)
);
ALTERTABLE persons ADD CHECK (age>=18)
ALTERTABLE persons DROP CHECK (age>=18)
The following tests should be passed:
test_case!(enum_data_type, async move {let test_cases = [("CREATE TABLE persons (name VARCHAR(40), age INTEGER CHECK (age>=18))",
Ok(Payload::Create),
),
("INSERT INTO persons VALUES ('minsu', 20)",
Ok(Payload::Insert(1)),
),
("INSERT INTO persons VALUES ('younghee', 10)",
Err(ValueError::NotEnumValue("invalid input value for check age: \"10\"".to_string(),
)),
),
("ALTER TABLE persons DROP CHECK (age>=18)",
Ok(Payload::AlterTable),
),
("INSERT INTO persons VALUES ('kim', 10)",
Ok(Payload::Insert(1)),
)];
for(sql, expected) in test_cases {
test!(expected, sql);
}});
Description
The CHECK constraint is used to limit the value range that can be placed in a column.
If you define a CHECK constraint on a column it will allow only certain values for this column.
If you define a CHECK constraint on a table it can limit the values in certain columns based on values in other columns in the row.
Example
The following tests should be passed:
Reference
https://www.w3schools.com/sql/sql_check.asp
https://dev.mysql.com/doc/refman/8.0/en/create-table-check-constraints.html
https://www.postgresql.org/docs/current/ddl-constraints.html
The text was updated successfully, but these errors were encountered: