如何在Derby中将关键字用作列名 [英] How to use keywords as column names in Derby

查看:108
本文介绍了如何在Derby中将关键字用作列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在Derby中使用保留关键字作为列名吗?
我正在尝试将数据库架构迁移到Derby中以进行测试。因此,我真的不想更改架构结构(列名称等)。

Can I use reserved keywords as column names in Derby? I'm trying to migrate database schema into Derby for testing purposes. For that reason I don't really want to change the schema structure (column names etc).

所以问题是,如何在Derby中创建列名为 open的表?例如表:

So the question is, how can I create table with column name "open" in Derby? As for example table:

create table test ( open integer );

试图引用列名,但到目前为止没有成功...

Tried to quote the column name, but so far no success...

java.sql.SQLSyntaxErrorException: Syntax error: Encountered "open" at line 1, column 21.
    at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)


推荐答案

引用保留字的标准方法(Derby遵循该标准,几乎所有DBMS都遵循该标准)是使用双引号。

The standard way of quoting reserved words (and Derby follows the standard as nearly all DBMS do in that regard) is to use double quotes.

create table test ( "OPEN" integer );

但是请注意,一旦执行该操作,列(或表)名称就会区分大小写。 OPEN open Open

But beware that once you do that column (or table) names become case-sensitive. "OPEN" is a different column than "open" or "Open".

我强烈建议您不要使用需要您引用它们的名称。

I would strongly suggest you do not use names that require you to quote them.

这篇关于如何在Derby中将关键字用作列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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