postgresql - Update field in multiple tables by foreign key constraint? -


asume have schema this:

create table "user" (   id bigserial primary key,   sid varchar(32) not null,   active boolean not null default true,   login varchar(32) not null, );  create table user_authority_relation (     id bigserial primary key,     user_id int8 not null,     authority_id int8 not null,     constraint user_fk foreign key (user_id)     references "user" (id) on delete cascade,     constraint authority_fk foreign key (authority_id)     references "authority" (id) on delete cascade,     unique (user_id, authority_id) );  create table note (   id bigserial primary key,   content text not null,   sender_id int8 not null,   sent_date timestamp without time zone not null,   important boolean not null,   type varchar(16) not null,   constraint user_fk foreign key (sender_id)   references "user" (id) on delete cascade deferrable immediate ); 

now, must delete user x db, instead of delete related objects want replace id new user y. example if note.sender_id x.id want set y.id, same user_authority_relation.user_id want change x.id y.id.

is possible in sql/postgresql?

edit:

i have written broadly. know can write update like:

update user_authority_relation  set user_id = y.id 

but want achive 1 update on objects refers x constraint. db have on dozen tables refer user. don't want write update of them separately 1 update.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -