Chinaunix首页 | 论坛 | 博客
  • 博客访问: 415574
  • 博文数量: 88
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 1054
  • 用 户 组: 普通用户
  • 注册时间: 2012-11-07 12:23
文章分类
文章存档

2014年(88)

我的朋友

分类: Oracle

2014-06-17 14:31:10

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.
 

 
阅读(1238) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~