TheWizardofInt Posted October 30, 2006 Posted October 30, 2006 I have a Table called 'GridGroups' with a primary field 'GridGroupID' There is a secondary table called 'GridTrans' which also has a field, 'GridGroupID', which is not primary. This second table uses a ForeignKey relationship to the primary for the two GridGroupID's. Don't ask me why - not my database, and I don't like Foreign Keys for just this reason. Now I want to delete the GridGroups, so (and correct me if I am wrong) I should: 1. Delete all of the rows in GridTrans with this GridGroupID 2. THEN delete the one row in GridGroups with that GridGroupID I can do (1), (2) throws this error: Integrity constraint violation: Primary key for row in table 'GridGroups' is referenced by foreign key... Have I missed a step here? This, by the way, is a Sybase database Quote Read the Fovean Chronicles Because you just can't spend your whole day programming!
dinoboy Posted November 3, 2006 Posted November 3, 2006 If you can/may change the database and the FK, then you should set the FK delete rule to cascade. Cascade means that when you want to delete/update the row in primary table then the rows are updated/deleted from the tables with foreign key too. In your case you should then delete only from table GridGroups and matched rows from GridTrans would deleted automaticly. Other option, if you can't change the FK rule... You don't say in your error with which table the integrity constraint violation appears? I mean there may be other tables with FK's to GridGroups table. If so, then you can't delete from GridGroups unless you first delete all matching rows from all other tables with relations. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.