Declaring data types in SQLite

Posted by dan04 on Stack Overflow See other posts from Stack Overflow or by dan04
Published on 2010-03-13T00:30:19Z Indexed on 2010/03/13 0:37 UTC
Read the original article Hit count: 439

Filed under:
|

I'm familiar with how type affinity works in SQLite: You can declare column types as anything you want, and all that matters is whether the type name contains "INT", "CHAR", "FLOA", etc. But is there a commonly-used convention on what type names to use?

For example, if you have an integer column, is it better to distinguish between TINYINT, SMALLINT, MEDIUMINT, and BIGINT, or just declare everything as INTEGER?

So far, I've been using the following:

  • INTEGER
  • REAL
  • CHAR(n) -- for strings with a known fixed with
  • VARCHAR(n) -- for strings with a known maximum width
  • TEXT -- for all other strings
  • BLOB
  • BOOLEAN
  • DATE -- string in "YYYY-MM-DD" format
  • TIME -- string in "HH:MM:SS" format
  • TIMESTAMP -- string in "YYYY-MM-DD HH:MM:SS" format

(Note that the last three are contrary to the type affinity.)

© Stack Overflow or respective owner

Related posts about sqlite

Related posts about best-practices