2011-09-26 20 views
0

做SQLite數據庫使用像TEXT值的輕量級的模式什麼。如果我反覆使用列中的幾個不同的簡短TEXT值,用整數替換它們會更好嗎?TEXT值

回答

3

的SQLite存儲文本列的每個副本分別:

$ sqlite3 pancakes.sqlt 
sqlite> create table pancakes (s text); 
sqlite> insert into pancakes (s) values ('where is pancakes house?'); 
sqlite> insert into pancakes (s) values ('where is pancakes house?'); 
sqlite> insert into pancakes (s) values ('where is pancakes house?'); 
sqlite> insert into pancakes (s) values ('where is pancakes house?'); 
sqlite> insert into pancakes (s) values ('where is pancakes house?'); 
sqlite> insert into pancakes (s) values ('where is pancakes house?'); 
sqlite> insert into pancakes (s) values ('where is pancakes house?'); 
sqlite> insert into pancakes (s) values ('where is pancakes house?'); 

$ strings pancakes.sqlt 
SQLite format 3 
Itablepancakespancakes 
CREATE TABLE pancakes (s text) 
=where is pancakes house? 
=where is pancakes house? 
=where is pancakes house? 
=where is pancakes house? 
=where is pancakes house? 
=where is pancakes house? 
=where is pancakes house? 
=where is pancakes house? 

所以,如果你想避免重複你的字符串,你應該使用整數,建立一個單獨的表到你的整數映射到字符串,然後添加一個foreign key到這個新表,這樣就可以確保參照完整性。

+2

Nice FARGO參考。 – ajk

+1

@ajk:我放棄*富* * *煎餅*。 –