How to use keywords as column names in Derby

我是研究僧i 提交于 2019-12-23 18:43:03

问题


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).

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)

回答1:


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

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.



来源:https://stackoverflow.com/questions/13357511/how-to-use-keywords-as-column-names-in-derby

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