sql - Java DB / Derby - white space in table name - how to escape? -


java db / derby - white space in table (column) name - how escape? in mysql database escaped `` (grave accent), if trying execute query (java db) like:

create table `etc etc` (id int primary key, title varchar(12)) 

i error:

java.sql.sqlsyntaxerrorexception: lexical error @ line 1, column 14. encountered: "`" (96), after : "".

is there solution?

edited:

thanks comprehensive answers indeed. found interesting thing (java db):

it ok create table this:

create table "etc etc" (id int primary key, title varchar(12)) 

and later results:

select * "etc etc" 

but if create table (without white space , quotes):

create table etc_etc (id int primary key, title varchar(12)) 

and later results (with double quotes, example, don't needed):

select * "etc_etc" 

i error:

java.sql.sqlsyntaxerrorexception: table/view 'etc_etc' not exist.

so conclusion if quotes used while creating table (it not important if name contains white space or not), later, while getting results, quotes should used. , vice versa (int case of course without white space).

i agree better not use white space, instead _ character. liked on mysql ` grave accent characters...

the sql standard requires double quotes quote identifiers either reserved words or use characters otherwise not permitted in identifier. note mysql ignores standard using dreaded backtick ` - could (and in opinion should) configured allow standard double quotes (like other dbms do).

so statement should this:

create table "etc etc" (id int primary key, title varchar(12)); 

note use of "quoted identifiers" (or "delimited identifiers") makes name case sensitive. "etc etc" different table name "etc etc". after creating table above, always have write name in lowercase.

the best thing avoid quoted identifiers. in case should settle etc_etc name using underscore visually separate 2 words.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -