foreign key的一些總結

jeanron100發表於2012-10-14
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/23718752/viewspace-746378/,如需轉載,請註明出處,否則將追究法律責任。

相關文章