Most of the results I have seen were for MySQL. I understand that Alter Table
is to be used, as well as MODIFY
, but after that I am stuck
My table in question is this:
x
CREATE TABLE store_reps
(
rep_id NUMBER(5) PRIMARY KEY,
LastN VARCHAR2(15),
FirstN VARCHAR2(10),
comm CHAR(1) DEFAULT 'Y'
);
For the comm column, I want to set it where it can only allow either “Y” or “N”. I hope this is enough to help solve the problem.
Advertisement
Answer
You are looking for a check
constraint:
CREATE TABLE store_reps (
rep_id NUMBER(5) PRIMARY KEY,
LastN VARCHAR2(15),
FirstN VARCHAR2(10),
comm CHAR(1) DEFAULT 'Y',
CONSTRAINT chk_store_reps_comm CHECK (comm IN ('Y', 'N'))
);
Or after the table is created:
ALTER TABLE store_reps
ADD CONSTRAINT chk_store_reps_comm CHECK (comm IN ('Y', 'N'));