pl/sql [message #642800] |
Sun, 20 September 2015 08:32 |
|
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 #642803 is a reply to message #642800] |
Sun, 20 September 2015 10:07 |
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
|
|
|
|