sql - PSQL - how to insert data to the altered table? -
i have employee
table foreign key dno
refers dnumber
in department
table. in department
table there foreign key mgr_ssn
refers ssn
in employee
table.
i created table using
alter table employee add foreign key (dno) references department(dnumber) on delete restrict on update cascade;
(both dno , mgr_ssn not null)
but confused how insert data, because violates referential integrity constraint, suggestion?
thank :)
foreign keys not given "not null" constraint. if there new employee has not been assigned dept. or new dept no manager.
still, problem should use "deferrable" property of oracle constraints. means, constraint checked @ commit point only. can insert dno , empnos first, commit later. @ point there no constraint viokation fk exists.
alter table employee add foreign key (dno) references department(dnumber) deferred deferrable;
--do same dept
then, insert emp (...) insert dept(...) commit;
Comments
Post a Comment