开发者

Problem in creating trigger

I'm creating a trigger but get this error:

android.database.sqlite.SQLiteException: near "CREATE": syntax error: CREATE TRIGGER fk_item_place BEFORE 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)); FOR EACH ROW BEGIN SELECT CASE WHEN ((SELECT Place_ID FROM Place_Table WHERE Place_ID=new.PlaceIDfk ) IS NULL) THEN RAISE (ABORT开发者_Python百科,'Foreign Key Violation') END ; END ;

My code is this:

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 ;");

What am I doing wrong?


You can't have an ON CREATE TABLE trigger. Make sure Item_places is the table name, not it's DDL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜