When someone asked the difference between integer types in SQLITE:
What is the difference between SQLite integer data types like int, integer, bigint, etc.?
The answer declared it unimportant for SQLITE because:
SQLite uses a more general dynamic type system. In SQLite, the datatype of a value is associated with the value itself, not with its container.
A SqlLite "integer" can hold whatever you put into it: from a 1-byte char to an 8-byte long long.
When I think of storing integers into a container, the signature of the container can vary with the same value.
0000 0000 0000 0001 = 1
0000 0001 = 1
Conversely an unsigned integer and an integer can have the same signature but different values:
1111 1111 1111 1111 1111 1111 1111 1111 = -1
1111 1111 1111 1111 1111 1111 1111 1111 = 4294967295
And so I am a bit confused whether it matters for primary keys if I specify the type, because the manual states:
A primary key is a field in a table which uniquely identifies the each rows/records in a database table. Primary keys must contain unique values. A primary key column cannot have NULL values.
From this, I have to assume that declaring the specific integer type for a column, being one of:
INT
INTEGER
TINYINT
SMALLINT
MEDIUMINT
BIGINT
UNSIGNED BIG INT
INT2
INT8
is important because I assume that datatypes can have exact same signatures with different values and vice versa, thus violating the must contain unique values
specification somehow.
So ultimately my question is, will declaring the datatype of a primary key to be specifically be one of TINYINT SMALLINT, MEDIUMINT, BIGINT, UNSIGNED BIG INT, INT2, INT8
make any difference whatsoever?
I need to know this because I am making a key value store with SQLITE, and want to have the ability to set keys for all the possible datatypes. If there is no difference between TINYINT
and INTEGER
, then I won't bother having TINYINT
as a possible key datatype.