user2883256
user2883256

Reputation: 31

Check Constraint in oracle for yes or no

I have to create a table in an art gallery. the table is Art_Object. Among the various attributes, I am having trouble implementing a check constraint for a "Restoration" field where the only values for it can be "Yes" or "No". I have tried various versions of it with double quotations, single quotations, no quotations, making it equal the the field name (ex. Restoration = 'Yes') with no luck. I have also tried CHECK(Restoration IN('Yes', 'No'))... and this has not worked either. I am lost.

Upvotes: 1

Views: 8977

Answers (1)

Klas Lindbäck
Klas Lindbäck

Reputation: 33273

The syntax is like this:

CREATE TABLE Art_Object
(
  column1 datatype null/not null,
  column2 datatype null/not null,
  ...,

  CONSTRAINT check_restoration_yesno
    CHECK (Restoration = 'Yes' OR Restoration = 'No')
);

Upvotes: 4

Related Questions