需要外键帮助

时间:2013-05-04 20:01:23

标签: android

        db.execSQL(" CREATE TABLE " + KK_AIRLINEBOOK + " (" + KEY_ID
                + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_SrNo + " INTEGER, " + KEY_BNAME + " TEXT , "     
                 + KEY_Bookingdate
                + " TEXT, " + KEY_Pickupaddress + " TEXT, " + KEY_City
                + " TEXT, " + KEY_AirportType + " TEXT, "+ KEY_Trip + " TEXT, " + KEY_Cabr + " TEXT , "
                + KEY_FlightDate + " TEXT, " + KEY_FlightTime + " TEXT, " + KEY_CabDate
                + " TEXT, " + KEY_PickupTime + " TEXT, " + KEY_TotalSeats
                + " INTEGER, " + KEY_Charges + " INTEGER , "
                +  "FOREIGN KEY ," + KEY_SrNo + " REFERENCES  KK_REGISTRATION , " + KEY_ID +");");

Log Cat:

05-04 20:06:36.034: E/SQLiteLog(26155): (1) near ",": syntax error
05-04 20:06:36.364: E/AndroidRuntime(26155): FATAL EXCEPTION: main
05-04 20:06:36.364: E/AndroidRuntime(26155): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.raintek.customerhome/com.raintek.customerhome.Login}: android.database.sqlite.SQLiteException: near ",": syntax error (code 1): , while compiling: CREATE TABLE Airline (id INTEGER PRIMARY KEY AUTOINCREMENT, srno INTEGER, bname TEXT , bookingdate TEXT, pickupaddress TEXT, city TEXT, AirportType TEXT, trip TEXT, cab TEXT , flightdate TEXT, flighttime TEXT, cabdate TEXT, pickuptime TEXT, totalseats INTEGER, charges INTEGER , FOREIGN KEY ,srno REFERENCES  KK_REGISTRATION , id);
05-04 20:06:36.364: E/AndroidRuntime(26155):    at dalvik.system.NativeStart.main(Native Method)
05-04 20:06:36.364: E/AndroidRuntime(26155): Caused by: android.database.sqlite.SQLiteException: near ",": syntax error (code 1): , while compiling: CREATE TABLE Airline (id INTEGER PRIMARY KEY AUTOINCREMENT, srno INTEGER, bname TEXT , bookingdate TEXT, pickupaddress TEXT, city TEXT, AirportType TEXT, trip TEXT, cab TEXT , flightdate TEXT, flighttime TEXT, cabdate TEXT, pickuptime TEXT, totalseats INTEGER, charges INTEGER , FOREIGN KEY ,srno REFERENCES  KK_REGISTRATION , id);

如何在android sqlite中使用外键这是我的代码,但它显示“FOREIGN KEY”附近的语法错误上面的代码有什么问题请帮帮我 谢谢

1 个答案:

答案 0 :(得分:0)

FOREIGN KEY的格式如下:

FOREIGN KEY(srno) REFERENCES KK_REGISTRATION(id)

你有逗号。