The following code should have resulted in an error as the foreign key ISOid was not respected in the row insertion in table Zone. Am I correct or doing something wrong?
dbName = 'test.sqlite'; conn = sqlite(dbName,'create'); conn.exec('PRAGMA foreign_keys=ON') createISOTable = ... ['create table if not exists ', 'ISO', ... ' (ISOid INTEGER PRIMARY KEY AUTOINCREMENT, Name varchar(50))']; createZoneTable = ... ['create table if not exists ', 'Zone', ... ' (Zoneid INTEGER PRIMARY KEY AUTOINCREMENT,',... ' ISOid INTEGER,'... ' Name varchar(50),'... ' FOREIGN KEY(ISOid) REFERENCES ISO(ISOid)' ... ')']; createStationTable = ... ['create table if not exists ', 'Station', ... ' (Stationid INTEGER PRIMARY KEY AUTOINCREMENT, ZoneID Integer ,Name varchar(50), FOREIGN KEY(Zoneid) REFERENCES Zone(Zoneid))']; conn.exec(createISOTable); conn.exec(createZoneTable); conn.exec(createStationTable); conn.insert('Zone',{'ISOid','Name'},{2,'MyISOName'}); conn.fetch('select * from Zone'); conn.close
Best Answer