Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 29th, 2006, 09:55 AM
stevesoft stevesoft is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Location: ENGLAND
Posts: 3 stevesoft User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 m 9 sec
Reputation Power: 0
Send a message via MSN to stevesoft
Unhappy Cascade Deletes

Can anyone help me with setting up cascade deletes in a firebird database.

I am using Upscene's Database Workbench 2.8 for the database administration, and VB6 for the front-end application.

I've tried to setup a foreign key constraint and selected cascade delete, however it does not seem to work.

This is what i need to achieve;

I have two tables;

1) Ranges (with three fields)
RA_ID <-----Primary Key
RA_NAME
RA_DESC

2) Models (with four fields)
MO_ID <-----Primary Key
MO_NAME
MO_DESC
MO_RA_ID <----Foreign Key

the models belong to a range, and the field MO_RA_ID indicates which range it belongs to and needs to be linked to RA_ID in the ranges table.

If a range is deleted, all the models that belong to that range should also be deleted.

Last edited by stevesoft : May 29th, 2006 at 10:11 AM. Reason: more info

Reply With Quote
  #2  
Old May 29th, 2006, 10:30 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,906 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 6 h 56 m 54 sec
Reputation Power: 279
This is a simple example:
sql Code:
Original - sql Code
  1. CREATE TABLE TEST_HEADER(
  2.   FIRST_FIELD Varchar(10) NOT NULL COLLATE NONE,
  3.   PRIMARY KEY (FIRST_FIELD)
  4. );
sql Code:
Original - sql Code
  1. CREATE TABLE TEST_DETAILS(
  2.   FIRST_FIELD Varchar(10) NOT NULL COLLATE NONE,
  3.   SECOND_FIELD Varchar(10) NOT NULL COLLATE NONE,
  4.   PRIMARY KEY (FIRST_FIELD,SECOND_FIELD)
  5. );
Then add the FK
sql Code:
Original - sql Code
  1. ALTER TABLE TEST_DETAILS
  2. ADD CONSTRAINT FK_TEST_DETAILS_1 
  3. FOREIGN KEY (FIRST_FIELD) REFERENCES TEST_HEADER (FIRST_FIELD)
  4. ON UPDATE CASCADE ON DELETE CASCADE;

it works (check your commits )

Reply With Quote
  #3  
Old May 29th, 2006, 12:26 PM
stevesoft stevesoft is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Location: ENGLAND
Posts: 3 stevesoft User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 m 9 sec
Reputation Power: 0
Send a message via MSN to stevesoft
This is the SQL i try to execute;

sql Code:
Original - sql Code
  1. ALTER TABLE MODELS
  2. ADD CONSTAINT FK_MODELS_1
  3. FOREIGN KEY (MO_RA_ID) REFRENCES RANGES (RA_ID)
  4. ON UPDATE CASCADE
  5. ON DELETE CASCADE;

but then i get the following error;

Quote:
ISC ERROR CODE:335544466

ISC ERROR MESSAGE:
VIOLATION OF FOREIGN KEY CONSTRAINT "PK_RANGES" ON TABLE "RANGES"

Reply With Quote
  #4  
Old May 29th, 2006, 01:21 PM
stevesoft stevesoft is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Location: ENGLAND
Posts: 3 stevesoft User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 m 9 sec
Reputation Power: 0
Send a message via MSN to stevesoft
I Got It Working

I Deleted All The Data From Both Tables,
Added The Foreign Key, Which This Time Did Not Give The Error.
Then Re-generated All The Data

Now It Seems To Work Ok. I Think I Must Of Had Some Corrupt Data In There

Reply With Quote
  #5  
Old May 30th, 2006, 02:32 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,906 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 6 h 56 m 54 sec
Reputation Power: 279
Quote:
Originally Posted by stevesoft
I Got It Working
...
Now It Seems To Work Ok. I Think I Must Of Had Some Corrupt Data In There
Yes, that's what FK are for Glad you got it working

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > Cascade Deletes


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway