ITPub博客

首页 > 数据库 > Oracle > foreign key的一些总结

foreign key的一些总结

Oracle 作者:jianghaifuyun1987 时间:2014-03-21 14:51:56 0 删除 编辑
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.
 

 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/14300593/viewspace-1126718/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-03-07

  • 博文量
    75
  • 访问量
    74342