Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are valid table names in SQLite?

Tags:

sql

sqlite

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?

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.

like image 408
David Avatar asked Sep 12 '10 08:09

David


People also ask

What is a valid table name?

Table names can contain any valid characters (for example, spaces). If table names contain any characters except letters, numbers, and underscores, the name must be delimited by enclosing it in back quotes (`).

How do you name a table in SQLite?

To rename a table, the SQLite ALTER TABLE syntax is: ALTER TABLE table_name RENAME TO new_table_name; table_name. The table to rename.

Is valid SQL table name?

Table names must follow the rules for SQL Server identifiers, and be less than 128 characters. It is possible to force SQL Server to accept non-standard table names by surrounding them with square brackets but it is a very bad idea, because they have to be 'quoted' whenever they are used in scripts.

What are SQLite tables?

Introduction. Every SQLite database contains a single "schema table" that stores the schema for that database. The schema for a database is a description of all of the other tables, indexes, triggers, and views that are contained within the database.


2 Answers

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!?] 
like image 96
Guffa Avatar answered Oct 11 '22 12:10

Guffa


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.

like image 44
Matthew Flaschen Avatar answered Oct 11 '22 11:10

Matthew Flaschen