Steve Steve - 19 days ago 5
SQL Question

Creating sql for attribute with constraint

CREATE TABLE table_name(
id INT NOT NULL PRIMARY KEY,
Name TEXT,
Post TEXT,
Age INT LEN<68
)


How do i create that
Post
attribute where the constraint must be either Manager or clerk.

Answer

MySQL does not enforce check constraints. This leaves you with three options:

  1. You can create an enum with two values, 'manager' and 'clerk'.
  2. You can create a reference table that has two rows, and use a foreign key reference.
  3. You can create a trigger to check the values.

By the way, this line:

Age INT LEN<68

is not syntactically correct.