1

I'm trying to execute this statement in onUpgrade method of database helper but I'm getting an error:

 database.execSQL("CREATE TABLE VEHICLE_HOURS(ID INTEGER PRIMARY KEY AUTOINCREMENT, " +
            "MINUTES INTEGER, VEHICLE VARCHAR(255), ORDER INTEGER);");

ERROR

Caused by: android.database.sqlite.SQLiteException: near "ORDER": syntax error (code 1): , while compiling: CREATE TABLE VEHICLE_HOURS(ID INTEGER PRIMARY KEY AUTOINCREMENT, MINUTES INTEGER, VEHICLE VARCHAR(255), ORDER INTEGER);

Thanks.

4
  • order is a reserved word in SQL. Even if allowed, you should not sue it for a column name. Commented Feb 1, 2016 at 12:03
  • Order is a reserved word. "Order by", remember? Commented Feb 1, 2016 at 12:03
  • God... it's true. I knew it was a nonsense.. Thank you guys Commented Feb 1, 2016 at 12:07
  • Possible duplicate of What SQLite column name can be/cannot be? Commented Feb 1, 2016 at 12:09

1 Answer 1

3

ORDER is a reserved word in SQL. You could of course suppress that error by taking the name into quotes, like:

database.execSQL("CREATE TABLE VEHICLE_HOURS(ID INTEGER PRIMARY KEY AUTOINCREMENT, " +
        "MINUTES INTEGER, VEHICLE VARCHAR(255), \"ORDER\" INTEGER);");

but better just pick another column name, then nobody (including your future self) will hate you while maintaining this code.

Sign up to request clarification or add additional context in comments.

1 Comment

Got caught in this, I was trying to do the same & failed. Changed the table name & it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.