缺少右括号

时间:2015-05-13 13:58:14

标签: sql oracle

我创建了两个表int sql,但错误的右括号出现了原因?

create table  department(deptno number primary key,
                         deptname varchar(30) not null);

创建此表时发生错误

create table employee(eno number not null primary key,
                      fname varchar(30) not null,
                      lname varchar(30) not null,
                      job varchar(30) not null,
                      age number,
                      salary number(7,2),
                      comm number,
                      deptno number foreign key  references department(deptno),
                      address varchar(30) default 'new york');

2 个答案:

答案 0 :(得分:3)

要创建内联外键约束,您需要删除foreign key字词:

create table employee
(
   eno       number not null primary key,
   fname     varchar(30) not null,
   lname     varchar(30) not null,
   job       varchar(30) not null,
   age       number,
   salary    number(7, 2),
   comm      number,
   deptno    number references department(deptno),
   address   varchar(30) default 'new york'
);

答案 1 :(得分:1)

或者你可以这样做来控制你的约束名称:

create table employee
(
    eno       number not null,
    fname     varchar(30) not null,
    lname     varchar(30) not null,
    job       varchar(30) not null,
    age       number,
    salary    number(7, 2),
    comm      number,
    deptno    number,
    address   varchar(30) default 'new york',
    constraint pk_emp primary key (eno),
    constraint fk_emp_dep foreign key (deptno) references department(deptno)
);