0

Is there a way to predefine the values I want to be inserted in my table? I mean, for example I have this structure of the table

column1 | column2 | column3
        |         |
        |         |
        |         |

And I know that my column3 should contain only values for example YES, NO, and MAYBE

is there a way to define that in sql level, or the only way is to do it programatically?

To be more precise, I'm looking for something that will throw a database level exception if I insert a value that does not fall into my predefined range

P.S. I'm using a MySql database

vcmkrtchyan
  • 2,536
  • 5
  • 30
  • 59

2 Answers2

3

Use enumeration to set specific values for a column :

CREATE TABLE sizes (
    name ENUM('small', 'medium', 'large')
);
KAD
  • 10,972
  • 4
  • 31
  • 73
  • 1
    After the OP edited his question to make it more specific, this is the clear answer. After creating this, refer to this table from the original using a foreign key. – TheSmartWon Jun 30 '15 at 22:13
1

Why don't you create another table where you define YES, NO, MAYBE and refer to it using foreign key ?

Alp
  • 3,027
  • 1
  • 13
  • 28