sql - Update Parent and Child Table Simultaneously -


i need update column in 2 tables joined primary/foreign key. problem when try update either table separately, either of following (dependant upon table try , update):

ora-02292: integrity constraint (urms.emsr_ems_fk) violated - child record found

or

ora-02291: integrity constraint (urms.emsr_ems_fk) violated - parent key not found

is there way update both tables @ same time new value? solution i've found copy existing rows , insert these new rows, can updated -- old rows can deleted.

is solution or there easier way around this?

you have few options workarounds.

  • change constraint deferrable constraint , defer it. causes key checked on commit time rather update time.
  • update foreign key null first, update primary key, update foreign key again. assumes no not null constraint
  • if worse comes worse, create record (let's give reserved id of 0 can detect , avoid conflicts), update foreign key that, update primary key, update foreign key, delete record.

however there no way create statement updates both @ same time in oracle might have on update cascade in other databases.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -