7

When i execute sql commands, i.e. create table inside java code, does it matter if i write :

db.execSQL("create table mytable ("
                    + "scores int, "
                    + ");");
        }

Or this:

db.execSQL("create table mytable ("
                        + "scores INTEGER,"
                        + ");");
            }

Or it is both same thing, just different syntax?

ERJAN
  • 23,696
  • 23
  • 72
  • 146
  • 3
    Which sqlite version? – Developer Marius Žilėnas Aug 28 '15 at 04:55
  • 3
    Related: (SQLite version is important!) http://stackoverflow.com/questions/20289410/difference-between-int-primary-key-and-integer-primary-key-sqlite/20289487#20289487 – Thilo Aug 28 '15 at 05:18
  • 5
    They both result in a column with INTEGER affinity. In fact, anything that contains the string "int" will do, including things that are not normally used as column types in SQL like "pr**int**er" or "t**int**edwindows" (no, this is not a joke) – Karakuri Aug 28 '15 at 05:19
  • 3
    @Karakuri: And to make things even more confusing, the column type “**floa**ting po**int**” has integer affinity because the “int” in “point” has precedence over “float”. – dan04 Aug 28 '15 at 23:00

1 Answers1

6

Sqlite3 documentation says if you use INT then the column has "resulting affinity" : INTEGER. Typenames INT, INTEGER, TINYINT, SMALLINT, MEDIUMINT, BIGINT, UNSIGNED BIG INT, INT2, INT8 from the CREATE TABLE statement or CAST expression: give INTEGER affinity for the column.

For Sqlite2 see this answer

Community
  • 1
  • 1
  • this answer is more detailed than mine , although it gives same link i gave in comment below. i will accept it – ERJAN Aug 28 '15 at 09:21
  • 1
    Note that a column that's an alias of the ROWID (i.e., an `INTEGER PRIMARY KEY` in a table that's *not* declared `WITHOUT ROWID`) is *required* to contain integers rather than merely having integer *affinity*. This special case only applies when the type name is exactly `INTEGER`; an `INT PRIMARY KEY` is merely a normal integer-affinity column with a unique constraint. – dan04 Aug 28 '15 at 22:57