문제

I am creating a table in oracle DB and trying to add constraint so that the numbers allowed in the column are 1,2,3.

CREATE TABLE "TABLE_EXAMPLE"
(
.
.
"PROTOCOL" NUMBER (1,2,3),

....)

CONSTRAINT "CH1"
        CHECK ("PROTOCOL" BETWEEN 1 AND 3),

Am I doing right or any better way?

도움이 되었습니까?

해결책

CREATE TABLE TABLE_EXAMPLE 
(
 ...
  PROTOCOL NUMBER(1) NOT NULL CONSTRAINT CH1 CHECK (PROTOCOL IN (1,2,3))
 ...
);

BETWEEN 1 AND 3 includes 1.5, 1.6, etc.

And I'd recommend not to use quotes " unless you have special characters in table or column names...

다른 팁

If you are going to check in the table level Check Constraint is the best way. because if you are inserting larger value then the check constraint ll throw the error.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top