473,385 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

foreign key constraints, cannot delete

How can a delete rows from a table that has foreign key constraints?
Here is how I have it set up.

I have 2 tables, tableA has fields and id's and tableB has fields that
reference tableA's id's. I'm not able to do this

BEGIN TRANSACTION;

DELETE FROM tableB
WHERE tableAid = 5;

DELETE FROM tableA
WHERE id = 5;

COMMIT TRANSATION;

Even though I delete everything from tableB that references tableA, I
can't delete the field from tableA.

Is this because of the begin and commit? Do I need to commit after each delete?

The only problem with commiting after each is, if one fails for some
reason, I need it to rollback.
-Josh

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #1
4 9364
You havn't posted the exact error message. You'll have to if you want
people to properly explain what's going on...

On Fri, Oct 08, 2004 at 04:07:43PM -0500, Josh Close wrote:
How can a delete rows from a table that has foreign key constraints?
Here is how I have it set up.

I have 2 tables, tableA has fields and id's and tableB has fields that
reference tableA's id's. I'm not able to do this

BEGIN TRANSACTION;

DELETE FROM tableB
WHERE tableAid = 5;

DELETE FROM tableA
WHERE id = 5;

COMMIT TRANSATION;

Even though I delete everything from tableB that references tableA, I
can't delete the field from tableA.

Is this because of the begin and commit? Do I need to commit after each delete?

The only problem with commiting after each is, if one fails for some
reason, I need it to rollback.


-Josh

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html
--
Martijn van Oosterhout <kl*****@svana.org> http://svana.org/kleptog/ Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
tool for doing 5% of the work and then sitting around waiting for someone
else to do the other 95% so you can sue them.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFBZwNsY5Twig3Ge+YRAtTTAKDBgeyYUB+jn+p7iP171N 6l0UUm1ACgiV50
In1BKxwwwIAUdx35t3nX9lg=
=PUl9
-----END PGP SIGNATURE-----

Nov 23 '05 #2
On Fri, 8 Oct 2004 23:15:24 +0200, Martijn van Oosterhout
<kl*****@svana.org> wrote:
You havn't posted the exact error message. You'll have to if you want
people to properly explain what's going on...


update or delete on "tblheadings" violates foreign key constraint "$1"
on "tblheadings" DETAIL: Key (iid)=(22) is still referenced from table
"tblheadings"

-Josh

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #3
On Fri, Oct 08, 2004 at 04:21:01PM -0500, Josh Close wrote:
On Fri, 8 Oct 2004 23:15:24 +0200, Martijn van Oosterhout
<kl*****@svana.org> wrote:
You havn't posted the exact error message. You'll have to if you want
people to properly explain what's going on...


update or delete on "tblheadings" violates foreign key constraint "$1"
on "tblheadings" DETAIL: Key (iid)=(22) is still referenced from table
"tblheadings"


This looks like tblheadings has a foreign key reference to itself.
Is this the *exact* error message, cut-and-pasted? What do your
table definitions look like?

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #4
On Fri, 8 Oct 2004 18:14:50 -0600, Michael Fuhr <mi**@fuhr.org> wrote:
This looks like tblheadings has a foreign key reference to itself.
Is this the *exact* error message, cut-and-pasted? What do your
table definitions look like?

--
Michael Fuhr


There isn't a foreign key reference to itself. I figured out the
problem. I had to print out all the queries and manually figure out
the data that was being deleted. Turns out there was one value the
wasn't being removed. So the begin and commit do work like they
should.

Thanks.

-Josh

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: David | last post by:
I have a problem that I cannot delete components that are placed on a R\abbed page in Visual Basic.Net 2003. The form uses a Tab Control with several pages. I have a Panel on the page and then...
5
by: Alex | last post by:
Hi, hi have a table with 2.5 million records which i try do delete. i have several constraints on it too. i tried to delete the records using delete but it does not seem to work. the delete runs...
13
by: Bob Stearns | last post by:
Why is the following constraint invalid? I want to make sure that every row in IS3.ANIMALS_PRIV_INDEXES matches one of those in IS3.table_var_defn with part of the primary key fixed. Since this is...
3
by: Bob Darlington | last post by:
Using Access 2002. I have imported one form and two modules from another database, in order to compare code. Having finished the comparison, I cannot delete them. When I press 'Delete', I get a...
2
by: Natan | last post by:
I'm getting this exception when trying to delete a file: System.UnauthorizedAccessException: Access to the path "d:\root\sigma\anexos\" is denied. the thing is that i can save files in this...
8
by: wespvp | last post by:
I am using PostgreSQL 7.4.1 on RedHat 7.2. The query I am executing is something like (I replaced all the return values with 'count'): db=> explain select count(*) from messages m join (select...
1
by: ben | last post by:
Hi, I am using php to make a directory (to store all of the users files for the site), and it works fine mkdir("/home/fullpathtomyserver/public_html/users/$users_id/", 0777); It makes the...
4
smiley22
by: smiley22 | last post by:
hi guys, i had a problem with my codes, the problem is I cannot delete the inputs in the first 3 fields if I want to delete it. Here is the code: <head> <script language="JavaScript"> ...
2
by: SCPOS | last post by:
Cannot delete X: It is being used by another person or program. Close any programs that might be using the file and try again. Of course I have tried closing any programs I know of that may be...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.