我正在创建一个触发器但是会收到此错误:
android.database.sqlite.SQLiteException:near“CREATE”:语法错误:CREATE TRIGGER fk_item_place在INSERT ON CREATE TABLE之前Item_Place(PlaceIDfk INTEGER,ItemID NTEGER,FOREIGN KEY(PlaceIDfk)REFERENCES Place_Table(Place_ID)ON DELETE CASCADE FOREIGN KEY (ItemID)REFERENCES ContentTable(ContentID));对于每行开始选择情况((从Place_Table中选择Place_ID,其中Place_ID = new.PlaceIDfk)IS NULL)然后上升(ABORT,'外键违规')END;结束;
我的代码是:
db.execSQL("CREATE TRIGGER fk_item_place " +
" BEFORE INSERT "+
" ON "+ Item_places +
" FOR EACH ROW BEGIN "+
" SELECT CASE WHEN ((SELECT "+ PlaceID +" FROM "+ PlaceTable +" WHERE "+ PlaceID +"=new." + place_id + " ) IS NULL)"+
" THEN RAISE (ABORT,'Foreign Key Violation') END ;" +
" END ;");
我做错了什么?
答案 0 :(得分:0)
您无法拥有ON CREATE TABLE
触发器。确保Item_places
是表名,而不是DDL。