foreign key的一些总结

foreign key

SQL> alter table dept modify(deptno primary key);
Table altered.
SQL> alter table emp1 add foreign key(deptno) references dept(deptno);
Table altered.
 
SQL> alter table emp add constraint fk_dept foreign key (deptno) references dept;
Table altered.
SQL> create table emp1(empno number(10) primary key,ename varchar2(101),deptno number(10),
  2  foreign key fk_dept references dept(deptno)
  3  );
foreign key fk_dept references dept(deptno)
            *
ERROR at line 2:
ORA-00906: missing left parenthesis
SQL> create table emp1(empno number(10) primary key,ename varchar2(101),deptno number(10),
  2  foreign key (deptno) references dept(deptno)
  3  );
Table created.
SQL> create table emp1(empno number(10),ename varchar2(101),deptno number(10),
  2  constraint fk_dept1 foreign key (deptno) references dept(deptno)
  3  );
Table created.

--drop table
SQL> drop table dept;                
drop table dept
           *
ERROR at line 1:
ORA-02449: unique/primary keys in table referenced by foreign keys
 
SQL> drop table dept cascade constraint;
Table dropped.
 

 
上一篇:Oracle首席执行官Hurd:云迁移由业务现实驱动 将有两大SaaS阵营


下一篇:郑州商品交易所与阿里云达成合作 推进核心数据分析平台建设