On 2016/09/02 4:05 PM, Dave Blake wrote:
Can I confirm that defining feilds as VARCHAR(20) rather than TEXT, if I
know I only want 20 chars or less, will result in a smaller database?
In addition to the other useful replies, you might actually be
interested in ensuring the text field in question won't have more than
20 characters of data, which you can achieve in 2 ways:
First, by adding a CHECK constraint:
https://www.sqlite.org/lang_createtable.html#ckconst
Perhaps something like: "SomeField" TEXT CHECK(LEN("SomeField") <= 20)
This will ensure the length is not higher than 20 but will FAIL the
INSERT/UPDATE if you try to upload a value with more than 20 Chars.
Another option is a TRIGGER on UPDATE or INSERT that might limit the
value in that column to 20 chars. This will not fail, but may just
truncate the value.
Note: This is a really bad thing to do in general DB design guidelines,
but your case might be special.
https://www.sqlite.org/lang_createtrigger.html
Cheers,
Ryan
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users