On 2015-03-09 09:42 PM, Drago, William @ CSG - NARDA-MITEQ wrote: > All, > > I want to modify my database so that deleting a row from a parent table will > delete all dependant rows in all child tables. According to this page: > > https://www.sqlite.org/foreignkeys.html > > It looks like I have to add ON DELETE CASCADE to the child keys of all child > tables. For example: > > FROM: > DatasetID INTEGER REFERENCES UUT_Info > > TO: > DatasetID INTEGER REFERENCES UUT_Info ON DELETE CASCADE > > Is this correct? > > If so, do I have to create a new database and repopulate it or is there a way > to edit the existing database from the command shell?
There is always a way - but it is dangerous. You could first execute the Pragma writable_schema and then select the sql form the schema table, edit it somewhere and then update it back into the table: PRAGMA writable_schema = 1; -- On SELECT sql FROM "sqlite_master" WHERE name='MyTable' AND type='table'; ... ... UPDATE "sqlite_master" SET sql='CREATE TABLE MyTable (..new table schema here...)' WHERE name='MyTable' AND type='table'; PRAGMA writable_schema = 0; -- Off This is highly dangerous for Obvious reasons, be sure to backup first and never change the column meta values or order.