Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between related SQLite data-types like INT, INTEGER, SMALLINT and TINYINT?

Tags:

sqlite

When creating a table in SQLite3, I get confused when confronted with all the possible datatypes which imply similar contents, so could anyone tell me the difference between the following data-types?

INT, INTEGER, SMALLINT, TINYINT  DEC, DECIMAL  LONGCHAR, LONGVARCHAR  DATETIME, SMALLDATETIME 

Is there some documentation somewhere which lists the min./max. capacities of the various data-types? For example, I guess smallint holds a larger maximum value than tinyint, but a smaller value than integer, but I have no idea of what these capacities are.

like image 910
Alan Harris-Reid Avatar asked May 03 '10 22:05

Alan Harris-Reid


People also ask

What is the difference between int and INTEGER in SQLite?

However, the dynamic typing in SQLite allows it to do things which are not possible in traditional rigidly typed databases. So in MS Sql Server (for example), an "int" == "integer" == 4 bytes/32 bits. In contrast, a SqlLite "integer" can hold whatever you put into it: from a 1-byte char to an 8-byte long long.

What are the 4 main data types in SQLite3?

SQLite only has four primitive data types: INTEGER, REAL, TEXT, and BLOB. APIs that return database values as an object will only ever return one of these four types. Additional . NET types are supported by Microsoft.

What is data type Smallint in SQL?

The SMALLINT data type stores small whole numbers that range from –32,767 to 32,767. The maximum negative number, –32,768, is a reserved value and cannot be used. The SMALLINT value is stored as a signed binary integer. Integer columns typically store counts, quantities, and so on.


1 Answers

SQLite, technically, has no data types, there are storage classes in a manifest typing system, and yeah, it's confusing if you're used to traditional RDBMSes. Everything, internally, is stored as text. Data types are coerced/converted into various storage locations based on affinities (ala data types assigned to columns).

The best thing that I'd recommend you do is to :

  1. Temporarily forget everything you used to know about standalone database datatypes

  2. Read the above link from the SQLite site.

  3. Take the types based off of your old schema, and see what they'd map to in SQLite

  4. Migrate all the data to the SQLite database.

Note: The datatype limitations can be cumbersome, especially if you add time durations, or dates, or things of that nature in SQL. SQLite has very few built-in functions for that sort of thing. However, SQLite does provide an easy way for you to make your own built-in functions for adding time durations and things of that nature, through the sqlite3_create_function library function. You would use that facility in place of traditional stored procedures.

like image 138
J. Polfer Avatar answered Sep 26 '22 05:09

J. Polfer