2

I am designing a relational database schema that may be ported to multiple database platforms--SQLite3, PostgreSQL and MySQL and possibly others.

I would like to create table names that would be portable across all the database platforms. What are naming restrictions should I follow?

  • What characters are allowed?
  • What characters are allowed to begin the name?
  • What is the maximum length?
  • Are there other restrictions I should be aware of?

Thanks

momeara
  • 1,341
  • 2
  • 17
  • 29

1 Answers1

3

/^[a-zA-Z][a-zA-Z0-9_]{,9}$/ is generally safe.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • Even SQL-86 allowed (mandated) 18 characters for object names - it might only have mandated 8 characters for schema names. More recently, you can usually use 31 characters for object names. – Jonathan Leffler Mar 12 '11 at 03:45
  • If for some management reason you have to deal with .dbf files, you only get 10 characters to play with. – Ignacio Vazquez-Abrams Mar 12 '11 at 03:46
  • Just to be clear you are suggesting names that match the given regular expression. What is the "{,9}" mean? – momeara Mar 12 '11 at 03:48
  • A variable 0 to 9 repeats of the immediately-preceding expression. So, 1 to 10 characters (although you have deeper problems if you use less than 3 [other than "id"]). – Ignacio Vazquez-Abrams Mar 12 '11 at 03:49