Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a prefered way to specify a text column in SQLite?

Since the SQLite engine will not truncate the data you store in a text column, is there any advantage in being specific with column sizes when you define your schema? Would anyone prefer this:

CREATE TABLE contact(
 id    INTEGER PRIMARY KEY, 
 name  VARCHAR(45),
 title VARCHAR(10)
);

over this:

CREATE TABLE contact(
 id    INTEGER PRIMARY KEY, 
 name  TEXT,
 title TEXT
);

Why?

Are there advantages to not being specific?

like image 768
Jannie Theunissen Avatar asked Oct 13 '22 19:10

Jannie Theunissen


1 Answers

The advantage of using varchar(x) is that it is compatible with other database systems - if I remember correctly, TEXT isn't a standard SQL datatype.

Other than being more standards-compliant, there is indeed no difference whether you use TEXT or VARCHAR. More info at http://sqlite.org/datatype3.html

like image 164
Gabriel Reid Avatar answered Oct 26 '22 21:10

Gabriel Reid