本文共 703 字,大约阅读时间需要 2 分钟。
1.creation of table to create a primary key & foreign
HR@prod> create table dept (did number primary key,dname varchar2(20));
Table created.
HR@prod> create table emp (empno number,name varchar2(20),did number,
constraint emp_did_fk foreign key(did) references dept(did));
2.add a constraint to a table
HR@prod> drop table emp purge;
Table dropped.
HR@prod> drop table dept purge;
Table dropped.
HR@prod> create table dept as select * from departments;
Table created.
HR@prod> create table emp as select * from employees;
Table created.
HR@prod> alter table dept add primary key(department_id);
HR@prod> alter table emp add constraint emp_did_fk
foreign key(department_id) references dept(department_id)
转载地址:http://iknva.baihongyu.com/