1

I created a table using the following statement.

create table constraint_test(name varchar(20), city varchar(20) not null check (city in ('chennai','vellore')), phone numeric(10));

But when I insert as,

insert into constraint_test values('abcd,'ooty',123456);

it gets stored. How can I restrict it?

Naveen Kumar V
  • 2,559
  • 2
  • 29
  • 43

1 Answers1

2

How about

city ENUM('chennai', 'vellore')

or maybe

city ENUM('UNKNOWN', 'chennai', 'vellore')

Or you could use a TRIGGER.

Or you could implement the check in your application code. After all, not everything can be done in SQL.

Rick James
  • 135,179
  • 13
  • 127
  • 222