SQL检查约束多个条件

时间:2015-02-20 11:13:33

标签: sql

除了gm和捕手之外,球队已经确定了一名球员      名称不得超过10个字母。将其实现为检查约束。

表:(表名:empbbb02) EMPNO ENAME

EMPNO ENAME      POS          BOSS HIREDATE         SAL     DEPTNO INCENTIVES
----- ---------- ------------ ---- --------- ---------- ---------- ----------
712   rickey     gm                01-JAN-98      10000         40
735   lasorda    coach        712  10-JAN-98       2000         40
707   bochy      coach        712  11-JAN-98       2000         40
798   berra      coach        712  12-JAN-98       2000         40
782   musial     right field  707  01-FEB-98      42000         20
763   gehrig     first base   735  11-MAR-98      85000         10
777   minoso     shortstop    735  05-MAY-98      85000         10       6000
721   sandberg   second base  735  28-FEB-98      25000         10
788   cey        third base   735  10-JAN-99      15000         10       8000
720   williams   left field   707  05-JAN-99      15000         20
755   johnson    pitcher      798  08-NOV-98      50000         30

1 个答案:

答案 0 :(得分:0)

您需要在表格中添加检查约束:

alter table empbbb02 add check (char_length(ename) <= 10 or pos in ('gm','catcher'))