Derby数据库表列名称格式在查询中不一致 [英] Derby Database Table Column Name Format Inconsistent in Query

查看:268
本文介绍了Derby数据库表列名称格式在查询中不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查询Derby数据库时,我发现对于一些表,我必须双引号列名称并使用表名来限定列名,但是对于一些其他表,我不需要。这些表会发生什么,如何使所有表相同,并且可以查询它们,而不需要双引号和表名限定符?我使用NetBeans IDE的Sql Command工具。以下是这些不同的查询。

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’;


推荐答案

将tablename或列名称放在引号中通过术语分隔标识符执行两项操作:

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


  1. 允许您使用否则为保留关键字的单词命名列WHERE或SELECT)

  2. 指示数据库系统使用敏感规则处理名称,而不是不区分大小写规则

  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

因此,如果您最初使用CREATE TABLE语句创建table3,并在双引号中指定table3这个,那么你永远都要用双引号引用它的名字。

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

由数据库处理,如同

select * from TABLE3

while

select * fromtable3

将成功匹配您创建的表创建表table3

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

href =http://db.apache.org/derby/docs/10.9/ref/crefsqlj34834.html =nofollow> http://db.apache.org/derby/docs/10.9/ref/crefsqlj34834 .html

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

这篇关于Derby数据库表列名称格式在查询中不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆