我尝试在
中添加此sql检查ALTER TABLE School
add Role check_role
CHECK (check_role IN ('Teaching Assistant', 'Lecturer', 'Professor'));
我收到以下错误
ERROR at line 3:
ORA-02438: Column check constraint cannot reference other columns
SQL> desc School;
Name Null? Type
----------------------------------------- -------- ----------------------------
STAFFNUM NOT NULL VARCHAR2(12)
NAME NOT NULL VARCHAR2(50)
ADDRESS NOT NULL VARCHAR2(300)
DOB DATE
我正在尝试使用检查约束check_role
添加列调用Role我正在使用Oracle SQL。
感谢您的帮助!
答案 0 :(得分:5)
将角色列添加到表
alter table School
add (Role varchar(10));
向Role列添加约束。
alter table School
add constraint check_role
check (Role IN ('Teaching Assistant', 'Lecturer', 'Professor'));
======
ALTER TABLE School ADD COLUMN Role VARCHAR(50)
CONSTRAINT check_role CHECK
(Role IN ('Teaching Assistant', 'Lecturer', 'Professor'));