1

How can i make it so that with a MySQL column you can only input certain options i.e. 'YES', 'NO'

I know this is possible but i can't find how to do this and searching online hasn't helped!

Thank you,

1
  • Using a before insert trigger. Commented Nov 5, 2014 at 18:05

1 Answer 1

3

The cleanest way of doing this is probably to define an enum type:

CREATE TABLE my_table (
    my_column ENUM('YES', 'NO')
);
Sign up to request clarification or add additional context in comments.

2 Comments

A tinyint(1) with a value of 1 or 0 will also work, but which is more optimized?
you need to use set sql_mode='STRICT_ALL_TABLES'; then otherwise no error will be raised in case of wrong value

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.