简体   繁体   English

在SQL表名中包含数字的好或坏主意?

[英]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. 很明显,您可以在SQL表名中使用数字字符并使用它们,只要它们不在开头即可。 (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. (这里有一个关于其中一个副作用的讨论: 使用数字表格的SQLite问题? )我正在瞄准的数据库是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'). 我正在设计一个报告数据库,通过描述报告来明确命名一些实体,报告以数字命名('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. 我总是担心数据库周围的辅助软件:驱动程序,ETL代码可能不适合使用非普通名称。 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? 我的问题很简单:是否有任何'陷阱'或角落案例会排除像PART_45_AUDIT这样的表名?

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. 如果PART_45_AUDIT确实是您正在建模的实体的最清晰的描述(这将是非常罕见的),那么在名称中间不应该有任何数字。 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"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM