SQLite 表和列名要求 [英] SQLite table and column name requirements
问题描述
我想知道 SQLite 在创建表时对表名和列名有什么限制.创建表 的文档说表名不能以sqlite_"开头,但是什么还有其他限制吗?是否有任何是有效的正式定义?
I'm wondering what constraints SQLite puts on table and column names when creating a table. The documentation for creating a table says that a table name can't begin with "sqlite_" but what other restrictions are there? Is there a formal definition anywhere of what is valid?
SQLite 似乎出人意料地接受,只要名称被引用.例如...
SQLite seems surprisingly accepting as long as the name is quoted. For example...
sqlite> create table 'name with spaces, punctuation & $pecial characters?'(x int);
sqlite> .tables
name with spaces, punctuation & $pecial characters?
推荐答案
如果您使用方括号或引号,您可以使用任何名称并且没有限制:
If you use brackets or quotes you can use any name and there is no restriction :
create table [--This is a_valid.table+name!?] (x int);
但是没有括号的表名应该是任何不以数字开头且不包含任何空格的字母数字组合.
But table names that don't have brackets around them should be any alphanumeric combination that doesn't start with a digit and does not contain any spaces.
您可以使用下划线和 $,但不能使用诸如 + - ?!* @ % ^ &# =/\ : " '
You can use underline and $ but you can not use symbols like: + - ? ! * @ % ^ & # = / \ : " '
这篇关于SQLite 表和列名要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!