SQL SQLite 中的有效表名是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3694276/
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 07:31:36  来源:igfitidea点击:

What are valid table names in SQLite?

sqlsqlite

提问by David

What are the combination of characters for a table name in SQLite to be valid? Are all combinations of alphanumerics (A-Z, a-z and 0-9) constitute a valid name?

SQLite 中表名的字符组合是什么才有效?是否所有字母数字组合(AZ、az 和 0-9)都构成有效名称?

Ex. CREATE TABLE 123abc(...);

What about a combination of alphanumerics with dashes "-" and periods ".", is that valid as well?

字母数字与破折号“-”和句点“.”的组合怎么样,这也有效吗?

Ex. CREATE TABLE 123abc.txt(...);
Ex. CREATE TABLE 123abc-ABC.txt(...);

Thank you.

谢谢你。

回答by Guffa

I haven't found a reference for it, but table names that are valid without using brackets around them should be any alphanumeric combination that doesn't start with a digit:

我还没有找到它的参考,但不使用括号的有效表名应该是任何不以数字开头的字母数字组合:

abc123 - valid
123abc - not valid
abc_123 - valid
_123abc - valid
abc-abc - not valid (looks like an expression)
abc.abc - not valid (looks like a database.table notation)

With brackets you should be able to use pretty much anything as a table name:

使用括号,您应该可以使用几乎任何东西作为表名:

[This should-be a_valid.table+name!?]

回答by Matthew Flaschen

All of these are allowed, but you may have to quote them in "".

所有这些都是允许的,但您可能必须在"".

sqlite> CREATE TABLE "123abc"(col);
sqlite> CREATE TABLE "123abc.txt"(col);
sqlite> CREATE TABLE "123abc-ABC.txt"(col);
sqlite> select tbl_name from sqlite_master;
123abc
123abc.txt
123abc-ABC.txt

In general, though, you should stick to the alphabet.

不过,一般而言,您应该坚持使用字母表。

回答by Wirawan Purwanto

From SQLite documentation on CREATE TABLE, the only names forbidden are those that begin with sqlite_:

关于 CREATE TABLE 的SQLite文档中,唯一被禁止的名称是那些以 开头的名称sqlite_

Table names that begin with "sqlite_" are reserved for internal use. It is an error to attempt to create a table with a name that starts with "sqlite_".

以“sqlite_”开头的表名保留供内部使用。尝试创建名称以“sqlite_”开头的表是错误的。

回答by eric.mcgregor

Per Clemens on the sqlite-users mailing list:

根据 sqlite-users 邮件列表中的 Clemens:

Everything is allowed, except names beginning with "sqlite_".

除了以“sqlite_”开头的名称外,一切都是允许的。

CREATE TABLE "TABLE"("#!@""'?\", "");

You can use keywords ("TABLE"), special characters (""#!@""'?\"), and even the empty string ("").

您可以使用关键字 ("TABLE")、特殊字符 (""#!@""'?\"),甚至空字符串 ("")。