SQL 什么是长字符串的最佳 SQLite 数据类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9755803/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 14:52:25  来源:igfitidea点击:

Whats the best SQLite data type for a long string

sqlsqlite

提问by sazr

In SQLite3 I am going to be storing a very long string that looks something like this:

在 SQLite3 中,我将存储一个很长的字符串,看起来像这样:

string linkList = "www.blah.com,www.meh.com,www.hah.com"; 

will definitely exceed 255 chars, will probably be over 1000 chars

肯定会超过 255 个字符,可能会超过 1000 个字符

Should the column linkListbe a varchar, TEXTor something else to store a string that will probably be longer than 1000 chars

如果该列linkList是一个varcharTEXT还是其他什么东西来存储一个字符串,可能会超过1000个字符

CREATE TABLE(uId INT PRIMARY KEY, linkList varchar);

What would be the best variable type to use for the column linkList?

用于列的最佳变量类型是linkList什么?

回答by Jord?o

You should use TEXT.

你应该使用TEXT.

Although, that's the same thing as VARCHAR:

虽然,这与以下内容相同VARCHAR

If the declared type of the column contains any of the strings "CHAR", "CLOB", or "TEXT" then that column has TEXT affinity. Notice that the type VARCHAR contains the string "CHAR" and is thus assigned TEXT affinity

如果列的声明类型包含任何字符串“CHAR”、“CLOB”或“TEXT”,则该列具有 TEXT 亲和性。请注意,类型 VARCHAR 包含字符串“CHAR”,因此被分配了 TEXT 亲和性

And also:

并且:

Note that numeric arguments in parentheses that following the type name (ex: "VARCHAR(255)") are ignored by SQLite - SQLite does not impose any length restrictions (other than the large global SQLITE_MAX_LENGTH limit) on the length of strings, BLOBs or numeric values.

请注意,SQLite 忽略类型名称后面括号中的数字参数(例如:“VARCHAR(255)”) - SQLite 不会对字符串、BLOB 或数值。

"SQLite does not impose any length restrictions"

“SQLite 不施加任何长度限制”

回答by krevedko

Actually, all data types in SQLite is no matter, all data will be stored as strings. You can execute query CREATE TABLE(uId INT PRIMARY KEY, linkList BlahBlahString);without any error. Data type in SQLite is for sql compability only

实际上,SQLite 中的所有数据类型都无关紧要,所有数据都将存储为字符串。您可以毫无错误地执行查询CREATE TABLE(uId INT PRIMARY KEY, linkList BlahBlahString);。SQLite 中的数据类型仅用于 sql 兼容性

回答by gifpif

Yor have 2 choices to store a long Stringin SQLite

你有 2 种选择来存储一个长StringSQLite

  1. TEXTtype - SQLite support very long text (I don't know exact number but I tested 33000char SQLite3)
  2. BLOBtype: You can use BLOBData type to hold long String.
  1. TEXT类型 - SQLite 支持很长的文本(我不知道确切的数字,但我测试了33000 个字符 SQLite3)
  2. BLOB类型:您可以使用BLOB数据类型来保存长字符串。