Home » SQL & PL/SQL » SQL & PL/SQL » Constraint Problem
Constraint Problem [message #1755] Mon, 27 May 2002 02:35 Go to next message
Yogita
Messages: 8
Registered: April 2002
Junior Member
I have 2 tables say A and B and both have column A1(of same datatype), Table A has column A0 as the primary key. Now, while creating Table B ,column A1 of table B has this constraint -value should be from A1 of table A. How do I write this constraint?
Re: Constraint Problem [message #1757 is a reply to message #1755] Mon, 27 May 2002 06:21 Go to previous message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
SQL> create table a
2 (id number primary key);

Table created.

SQL> create table b
2 (id number references a(id));

Table created.

SQL> insert into a values
2 (&id);
Enter value for id: 1
old 2: (&id)
new 2: (1)

1 row created.

SQL> /
Enter value for id: 2
old 2: (&id)
new 2: (2)

1 row created.

SQL> /
Enter value for id: 3
old 2: (&id)
new 2: (3)

1 row created.

SQL> /
Enter value for id: 5
old 2: (&id)
new 2: (5)

1 row created.

SQL> commit;

Commit complete.

SQL> select * from a;

ID
----------
1
2
3
5

SQL> insert into b values (&id);
Enter value for id: 1
old 1: insert into b values (&id)
new 1: insert into b values (1)

1 row created.

SQL> /
Enter value for id: 7
old 1: insert into b values (&id)
new 1: insert into b values (7)
insert into b values (7)
*
ERROR at line 1:
ORA-02291: integrity constraint (MAG.SYS_C001513) violated - parent key not found

SQL>
Previous Topic: About computation on two columns values
Next Topic: storing/call procedures in pl/sql
Goto Forum:
  


Current Time: Thu Apr 25 06:12:22 CDT 2024