Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Delete from a table using Sql

Author  Topic 

g_p
Starting Member

48 Posts

Posted - 2007-01-31 : 19:54:20
Good evening everyone,I have a problem with deleting a record in a table.

I have the table:

create table Employee(eid integer not null,
shop_id integer,
fname varchar(20),
lname varchar(20),
primary key (eid),
foreign key (shop_id) references Store);

create table Store(sid integer,
address varchar(20),
primary key (sid));

I have inserted many Employees and when i do select they work fine.
The problem is with Delete e.g. i want to delete the Employee with Eid = 12 i do:

Delete from Employee where shop_id = '12'

and it says

ERROR at line 1:
ORA-02292: integrity constraint (user....) violated - child
record found




What do i do wrong?

g_p
Starting Member

48 Posts

Posted - 2007-01-31 : 19:55:55
I have made a mistake i want to

delete from Employee where eid = '12';

Sorry for that :)
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-01-31 : 20:03:36
You must delete all child data before deleting the parent row. Employee is a parent table. So you must go to all child tables and delete from them where eid = '12'. This is due to the foreign key constraints that have been setup to protect data integrity.

BTW, you can edit your posts rather than posting a correction in a new post. Just click the little pencil icon in the post to edit it.

Tara Kizer
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-02-01 : 00:02:02
ERROR at line 1:
ORA-02292: integrity constraint (user....) violated - child
record found

That looks like an Oracle error. You should really post you questions on an Oracle forum. This site is for Microsoft SQL Server questions.



CODO ERGO SUM
Go to Top of Page
   

- Advertisement -