Home » SQL & PL/SQL » SQL & PL/SQL » pl/sql
pl/sql [message #642800] Sun, 20 September 2015 08:32 Go to next message
ORA456
Messages: 7
Registered: September 2015
Location: HYDERABAD
Junior Member
hi to all

i have tables two tables these two tables having two columns

for example a and b tables
a table have two columns x primary key and y foreign key
b table have two columns y primary key and x foreign key
how insert data into those tables
Re: pl/sql [message #642801 is a reply to message #642800] Sun, 20 September 2015 08:54 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Please read and follow the forum guidelines, to enable us to help you:
OraFAQ Forum Guide
How to use {code} tags and make your code easier to read
Re: pl/sql [message #642802 is a reply to message #642800] Sun, 20 September 2015 09:01 Go to previous messageGo to next message
John Watson
Messages: 8929
Registered: January 2010
Location: Global Village
Senior Member
insert


--update:
I had thought that a simple multitable INSERT would do, but it doesn't. So you'll need to make the FKs deferrable.

[Updated on: Sun, 20 September 2015 09:14]

Report message to a moderator

Re: pl/sql [message #642803 is a reply to message #642800] Sun, 20 September 2015 10:07 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
Either insert + deferred constraint, as John suggested, or insert + update:

SQL> create table tbl1(
  2                    x number,
  3                    y number
  4                   )
  5  /

Table created.

SQL> create table tbl2(
  2                    y number,
  3                    x number
  4                   )
  5  /

Table created.

SQL> alter table tbl1
  2    add constraint tbl1_pk
  3      primary key(x)
  4  /

Table altered.

SQL> alter table tbl2
  2    add constraint tbl2_pk
  3      primary key(y)
  4  /

Table altered.

SQL> alter table tbl1
  2    add constraint tbl1_fk1
  3      foreign key(y)
  4      references tbl2
  5  /

Table altered.

SQL> alter table tbl2
  2    add constraint tbl2_fk1
  3      foreign key(x)
  4      references tbl1
  5  /

Table altered.

SQL> insert
  2    into tbl1(x)
  3    values(1)
  4  /

1 row created.

SQL> insert
  2    into tbl2(y)
  3    values(1)
  4  /

1 row created.

SQL> update tbl1
  2     set y = 1
  3   where x = 1
  4  /

1 row updated.

SQL> update tbl2
  2     set x = 1
  3   where y = 1
  4  /

1 row updated.

SQL> 


SY.

[Updated on: Sun, 20 September 2015 10:09]

Report message to a moderator

Re: pl/sql [message #642804 is a reply to message #642803] Sun, 20 September 2015 11:43 Go to previous message
ORA456
Messages: 7
Registered: September 2015
Location: HYDERABAD
Junior Member
thanks a lot boss Razz
Previous Topic: DBMS_OUTPUT
Next Topic: query same table multiple times
Goto Forum:
  


Current Time: Fri Apr 19 06:11:31 CDT 2024