Derby Database Table Column Name Format Inconsistent in Query

浪尽此生 提交于 2019-12-02 01:36:40

问题


When query a Derby database, I find out that for some tables I have to double quote the column name and use table name to qualify the column name, but for some other tables I don’t need to. What happens to these tables and how can I make all tables the same and can query them without the double quote and the table name qualifier? I am using NetBeans IDE’s Sql Command tool. Below are those different queries.

Set schema app;
Select * from table1 where table1.”state” = ‘CA’;
Select * from table2 where state = ‘CA’;

回答1:


Putting a tablename or column name in quotes, sometimes referred to by the jargon-y term "delimited identifiers" does two things:

  1. Allows you to use words that are otherwise reserved keywords (e.g., naming a column "WHERE" or "SELECT")
  2. Instructs the database system to process the name using case sensitive rules, rather than case-insensitive rules

So if you originally created "table3" with a CREATE TABLE statement that specified "table3" in double quotes like this, then you will forever after have to refer to it with the name in double quotes.

select * from table3

will be automatically processed by the database as if it was

select * from TABLE3

while

select * from "table3"

will successfully match the table you created as create table "table3"

See: http://db.apache.org/derby/docs/10.9/ref/crefsqlj34834.html



来源:https://stackoverflow.com/questions/12203787/derby-database-table-column-name-format-inconsistent-in-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!