oracle - SQL multiple insert select in one row -
i'm new in sql , i'm trying put values in table has 2 foreign keys.
create table room ( room_name varchar2(40 byte) , patient_id number , doc_name varchar2(50 byte) ) logging tablespace users pctfree 10 initrans 1 storage ( initial 65536 next 1048576 minextents 1 maxextents unlimited buffer_pool default ) noparallel; alter table room add constraint doc_room foreign key (doc_name) references doctor(doc_name) enable; alter table room add constraint patient_room foreign key (patient_id) references record(id) enable;
created using left panel in sql developer. can see have 2 foreign keys. have no idea how add values columns patient_id
, doc_name
.
so far did inserting 1 one table, resulted in having 3 different rows.
what got:
room_name | patient_id | doc_name --------------------------------------- emergency room | null | null null | 1 | null null | null | dr. john
what want get:
room_name | patient_id | doc_name --------------------------------------- emergency room | 1 | dr. john
insert
create new row (unless constraint violated).
to insert row values @ once, use this:
insert room (room_name, patient_id, doc_name) values ('emergency room', 1, 'dr. john');
if want change existing row, need use update
statement, e.g:
update room set doc_name = 'dr. house' room_name = 'emergency room' , patient_id = 1;
your room
table missing primary key, should add 1 uniquely identifies rows in table.
Comments
Post a Comment