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 4 9386
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
iD8DBQFBZwNsY5T wig3Ge+YRAtTTAK DBgeyYUB+jn+p7i P171N6l0UUm1ACg iV50
In1BKxwwwIAUdx3 5t3nX9lg=
=PUl9
-----END PGP SIGNATURE-----
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 "tblheading s" violates foreign key constraint "$1"
on "tblheading s" DETAIL: Key (iid)=(22) is still referenced from table
"tblheading s"
-Josh
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
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 "tblheading s" violates foreign key constraint "$1" on "tblheading s" DETAIL: Key (iid)=(22) is still referenced from table "tblheading s"
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*******@postg resql.org so that your
message can get through to the mailing list cleanly
On Fri, 8 Oct 2004 18:14:50 -0600, Michael Fuhr <mi**@fuhr.or g> 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 some combo boxes, labels and text boxes.
For some reason, I cannot delete any of these controls from the form (not
even the Tab control istelf).
The Delete and Cut options in the right click menu have been ghosted out as
is the options from Edit...
|
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 forever. hrs...
i cannot truncate it as it complains about foreign keys.
What is the problem ?
Thanks
|
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
illegal with the following message, how do I achieve this result? The
last thing below is a working constraint from another table.
ALTER TABLE IS3.ANIMALS_PRIV_INDEXES
ADD CONSTRAINT
FOREIGN KEY(3, variable_id)
REFERENCES...
|
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 message asking for confirmation 'Do you want
to permanently delete etc', I respond 'Yes' but the object remains. No error
message is generated.
If I try to open the object in design view, I get a message:
|
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 folder, but cannot delete.
I enabled the advanced folder security in XP, gave full access to ASPNET
and IUSR_MACHINENAME users to this folder. Finally I gave full access to
"All" user and tried impersonating.... no sucess..
| |
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 * from
message_recipients r join addresses a on a.Address_Key=r.Recipient where
a.Address='lra.edi@edi.cma-cgm.com') as foo on
(m.Message_Key=foo.Message_Key AND (m.Message_Date >= '29-MAR-04') AND
(m.Message_Date <= '31-MAR-04...
|
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 folder just perfect, BUT there is a flaw. The folders it
creates are un-deletable. I can browse them, and even link to files
within them, but I cannot delete them at all. I have tried deleting
|
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">
function switch_next(cur_obj,next){
if(cur_obj.value.length==3)
document.getElementById(next).focus();
|
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 using the file (used X because the filename does not matter...it is a specific log file name to the application).
I am logged onto a Windows Server 2003 computer that acts as a server for a LAN, but is physically joined to a domain.
The local...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| | |