Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Good or bad idea to include numbers in SQL table names?

It's clear that you can use numeric characters in SQL table names and use them so long as they're not at the beginning. (There's a discussion here on one of the side effects: SQLite issue with Table Names using numbers?) The database I'm targetting is Oracle 10g/11g.

I'm designing a reporting database where naming some of the entities clearly is best done by describing the reports, which are named after numbers ('part 45', '102S', '401'). It's just the business domain language: these reports just aren't commonly referred to by any other name. The entities I'm modelling really are best named this way.

My question is: am I going to have difficulties with maintenance or programmability if I put numbers in a table name? I'm always worried about ancillary software around the database: drivers, ETL code that might not play nice with a non-plain-vanilla name. But there's a real benefit in intelligibility in this business domain, so am I just being squeamish?

My question put simply is: are there any 'gotchas' or corner cases that would rule out a table name like PART_45_AUDIT?

like image 861
deepgeek Avatar asked Mar 29 '12 13:03

deepgeek


People also ask

Can table names have numbers SQL?

It's clear that you can use numeric characters in SQL table names and use them so long as they're not at the beginning.

Can table name contain numbers?

Tables usually do not have digits in their names, and if they do they have a special meaning. We use them to name backup tables with date of an backup (of single specific table while sensitive operation), archival tables with year or for partitioning tables.

What are the rules for naming a table in SQL?

The rules for naming database objects (such as tables, columns, views, and database procedures) are as follows: Names can contain only alphanumeric characters and must begin with an alphabetic character or an underscore (_). Database names must begin with an alphabetic character, and cannot begin with an underscore.


1 Answers

If PART_45_AUDIT is really the clearest description of the entity you're modeling (which would be very rare), there shouldn't be any gotchas to having numbers in the middle of a name. Putting numbers at the front of the name would be a different story because that would require using double-quoted identifiers and there are plenty of tools that don't fully support double-quoted identifiers. Plus, of course, it's rather annoying to have to type the double-quotes every time you reference the table.

CREATE TABLE "102S" (
  col1 number
);

SELECT *
  FROM "102S"
like image 83
Justin Cave Avatar answered Sep 30 '22 00:09

Justin Cave