Kuldeep Pal
Kuldeep Pal

Reputation: 47

SQL Oracle query Constraint

BranchNAME should be not null and can have any one of the listed values (Chennai, Mumbai,Delhi,Bangalore)

I can put single name in check how to put all cities names in check.

ALTER TABLE Employee ADD CONSTRAINT Branch CHECK (Branch= 'Delhi');

Upvotes: 0

Views: 588

Answers (1)

user330315
user330315

Reputation:

Use an IN condition:

ALTER TABLE Employee ADD CONSTRAINT check_branch_name
    CHECK (Branch IN ('Delhi','Chennai','Mumbai','Bangalore'));

and don't forget to add not null constraint

ALTER TABLE EMPLOYEE MODIFY BRANCH not null;

if not exists.

Upvotes: 3

Related Questions