New topic: 

Foreign Keys and cascading

<http://forums.realsoftware.com/viewtopic.php?t=38363>

         Page 1 of 1
   [ 2 posts ]                 Previous topic | Next topic          Author  
Message        MadDoc          Post subject: Foreign Keys and cascadingPosted: 
Mon Mar 28, 2011 12:17 pm                                 
Joined: Wed Oct 05, 2005 1:21 pm
Posts: 317
Location: United Kingdom                For simplicity sake, lets say I've got 
two tables: Exams and Subjects

Exams
-- ID Integer
-- Name Text

Subjects
-- ID Integer
-- Name Text
-- ExamID Integer

I'm trying to configure my REALSQLDatabase such that if I delete an exam entry 
from 'Exams' then any subjects in 'Subjects' belonging to that exam are also 
deleted.

Here's the SQL to create the tables:
Code:db.SQLExecute("CREATE TABLE Exams (ID Integer PRIMARY KEY, Name Text NOT 
NULL)")
db.SQLExecute("CREATE TABLE Subjects (ID Integer PRIMARY KEY, ExamID Integer 
REFERENCES Exams(ID) ON DELETE CASCADE ON UPDATE CASCADE, Name Text NOT NULL)")

I have db.AutoCommit set to True.

When I delete an exam, the subjects are still present.  The database isn't 
deleting them.  Am I doing something fundamentally wrong?  I'm relatively new 
to SQL so please be gentle...

Thanks,

MadDoc      
_________________
Figa Software | My Flickr | My Blog
MacBook Pro 2.53Ghz, 4GB RAM, OSX 10.6.4, RB 2010r5.1 Pro
Mac Mini 2.53Ghz, 4GB RAM, OSX 10.6.4 | iPhone 4 32GB | Nikon D60  
                             Top                simonjohn          Post 
subject: Re: Foreign Keys and cascadingPosted: Mon Mar 28, 2011 2:59 pm         
                        
Joined: Sat Apr 19, 2008 12:44 pm
Posts: 405
Location: Dorset, UK                After you've connected and set autocommit 
on - you may need to enable FK support for that connection:
Code:db.SQLExecute("PRAGMA foreign_keys= ON;")      
_________________
Simon Larkin
QiSQL Database Solutions 
SQL Tutorial  : http://qisql.com/qisql_sqlite_lessons.html  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 2 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to