Home » RDBMS Server » Server Utilities » foreign key
foreign key [message #69464] Fri, 11 January 2002 05:50 Go to next message
karen
Messages: 19
Registered: January 2002
Junior Member
hi
i have 2 tables:
one emp with a column eid being primary key
second dept table with col eid being foreign key
there is a line in the book like this:
"A table that is being referenced by a foreign key cannot be truncated"

that means acc. to it i cannot truncate dept table.right?
thanks!!
pl. answer this in terms that which table out of the above will not be truncated.
__________________
thanks a lot
Re: foreign key [message #69465 is a reply to message #69464] Fri, 11 January 2002 06:24 Go to previous messageGo to next message
Suresh Vemulapalli
Messages: 624
Registered: August 2000
Senior Member
you cant truncate parent table when child records exist.

For example:

emp:
eno number
ename varchar2
dno number - fk reference dept.dno

dept
dno number - pk
dname

assume data is like this

123,xyz,10
122,abc,20

dept :
10 x
20 y
30 z

you can delete 30 from dept table, not other two records because there are child records in emp table. same principle applies to truncate command.

remember, truncate delete all rows from table and commits the transaction.
Re: foreign key [message #69472 is a reply to message #69464] Mon, 14 January 2002 07:10 Go to previous messageGo to next message
karen
Messages: 19
Registered: January 2002
Junior Member
hi all,
thanx a lot for the answer.
actually i know the concept .the only thing is that the line is confusing me a lot.please try to explian in that terms only ,as to which table i can delete.
thanks a lot for your patience.
Re: foreign key [message #69501 is a reply to message #69464] Tue, 22 January 2002 03:35 Go to previous message
Vijay Kamath
Messages: 4
Registered: January 2002
Junior Member
Since eid is foriegn key in dept table and primary key in emp table, you cannot truncate emp table if corresponding records are present in dept.

emp cannot be truncated.
Previous Topic: Re: Access to Oracle
Next Topic: question
Goto Forum:
  


Current Time: Sat Mar 02 14:47:15 CST 2024