如何从sqlite3中的两个表中删除级联

时间:2014-04-27 17:53:33

标签: sqlite

我希望能够从军官表中删除一名军官,并且这样做会自动删除调查表中的军官调查。我的代码看起来是正确的,但它只会从人员表中删除官员,而不是从调查表中删除。有人可以告诉我我做错了吗?

queryCurs.execute('PRAGMA foreign_keys = ON')

queryCurs.execute('''CREATE TABLE Cases
                  (CID INTEGER PRIMARY KEY, Type TEXT, Description TEXT, Location TEXT, Ward INT)''')


queryCurs.execute('''CREATE TABLE Officers
                   (OID INTEGER PRIMARY KEY, Name TEXT, Team TEXT)''')

queryCurs.execute('''CREATE TABLE Investigation
                   ( CID INTEGER, OID INTEGER REFERENCES Officers(OID) ON DELETE CASCADE, DateInvolved DATE)''')

queryCurs = conn.cursor()


queryCurs.execute('''DELETE  FROM Officers WHERE OID = 1''')


createDb.commit()
createDb.close()

0 个答案:

没有答案