I have a text column that should only have 1 of 3 possible strings. To put a constraint on it, I would have to reference another table. Can I instead put the values of the constraint directly on the column without referring to another table?
Share
If this is SQL Server, Oracle, or PostgreSQL, yes, you can use a
check constraint.If it’s MySQL,
check constraints are recognized but not enforced. You can use anenum, though. If you need a comma-separated list, you can use aset.However, this is generally frowned upon, since it’s definitely not easy to maintain. Just best to create a lookup table and ensure referential integrity through that.