Turn off upper-case for table and column names in HSQL? - sql

How to turn off forced upper-case mode for table and column names in HSQL?
<artifactId>hsqldb</artifactId>
<version>2.3.1</version>
OS: Windows 7 x64

The rules around this are explained in the HSQLDB documentation:
When a database object is created with one of the CREATE statements or
renamed with the ALTER statement, if the name is enclosed in double
quotes, the exact name is used as the case-normal form. But if it is
not enclosed in double quotes, the name is converted to uppercase and
this uppercase version is stored in the database as the case-normal
form.
Case sensitivity rules for identifiers can be described simply as
follows:
all parts of SQL statements are converted to upper case before processing, except identifiers in double quotes and strings in single
quotes
identifiers, both unquoted and double quoted, are then treated as case-sensitive
most database engines follow the same rule, except, in some respects, MySQL and MS SQLServer.
AFAIK this behaviour can't be turned off. (It's worth noting that standard SQL is case-insensitive when quoted identifiers aren't used.) But as mentioned above, a lower case identifier can be specified by enclosing in quotes, e.g:
CREATE TABLE "lowercasetablename" ("lowercasecolname" INT);
SELECT "lowercasecolname" FROM "lowercasetablename";

I am not sure, i understand the problem correctly but just trying to put some effort.
SET DATABASE COLLATION SQL_TEXT_UCC
May be you can refer http://hsqldb.org/doc/guide/dbproperties-chapt.html

Related

is "SELECT fieldname, fieldName FROM MY_TABLE;" ever valid for any SQL database?

Do any SQL databases have case-sensitive naming for field names?
What I mean is, in Java you can have two variables ...
String fieldname = "a";
String fieldName = "b";
Are there any SQL databases support that so ...
SELECT fieldname, fieldName FROM MY_TABLE;
... would return two different columns?
I'm asking because I'm building a database utility that has to work for MySQL, H2, PostgreSQL, Oracle, and SQL Server, so I need to know how they all work for a bit of code I'm writing.
In most databases (and in all those you tagged), an unquoted identifier is case-insensitive. Meaning that fieldname and fieldName are the same thing: the database folds them into the default case, which makes them equivalent.
In most databases, you can make an identifier case-sensitive by quoting it. The quoting character varies across databases. In standard SQL, you use double quotes. So "fieldname" and "fieldName" are two different things. Oracle and Postgres follow that standard. SQL Server wants square brackets ([]); MySQL wants backticks.
In a nutshell: in SQL, I would not recommend using case-sensitive identifiers. This makes things more complicated for no value added. In my opinion, snake case style is your best pick in SQL, because upper/lower case are meaningless.
By the SQL standard, SQL identifiers are case-insensitive. So, without escape characters, these refer to the same column:
select fieldname, fieldName
However, you can escape the names and they become distinguishable. The standard SQL escape character is ":
select "fieldname", "fieldName"
But some databases don't support this and have their own.
In Oracle, you can certainly have case-sensitive column names, they just need to be quoted. So this query would return data from three separate columns
SELECT "columnName", "ColumnName", columnName
FROM table
In SQL Server, you can have case-sensitive columns but they need to be enclosed in brackets, i.e.
SELECT [ColumnName], [columnName], [columnname]
FROM table

Create mixed case table name/columns in oracle WITHOUT using quotes

Is there any way I can create a mixed case table name in Oracle without using quotes?
The table names change to uppercase if I do not use quotes while creating the table.
Let me know if you need more information.
Eg:
create table testTable(testColumn varchar);
This creates a table named TESTTABLE with column name TESTCOLUMN.
I can use quotes, but it makes it more messy and difficult to write queries.
Can you please let me know how I can do this without using quotes? Thanks.
Regards,
Sawan
Please refer to the official Oracle Database documentation:
"Nonquoted identifiers are not case sensitive. Oracle interprets them as uppercase."
https://docs.oracle.com/en/database/oracle/oracle-database/20/sqlrf/Database-Object-Names-and-Qualifiers.html#GUID-3C59E44A-5140-4BCA-B9E1-3039C8050C49
All the data dictionary views will show the identifiers as Oracle interprets them. In other words, without quotes everything will be uppercase. I can testify that this is true even for accented characters.
You can't always get what you want...

Escape table name in SQLite?

I have table named References in SQLite, so I can't target it, it seems. SQLite studio I use to edit databases throws an error.
Is there a way to escape database name?
The query is:
UPDATE References
SET DateTimeLastEdited = datetime('now', 'localtime')
WHERE NewsItemID = old.NewsItemID;
(This is part of the trigger I am making.)
You can escape table names with double quotes:
UPDATE "References" SET DateTimeLastEdited = datetime('now', 'localtime') WHERE NewsItemID = old.NewsItemID;
Depending on what you want to escape, you need to use different delimiters:
If you want to use a keyword as a name, you need to quote it. There
are four ways of quoting keywords in SQLite:
'keyword' A keyword in single quotes is a string literal.
"keyword" A keyword in double-quotes is an identifier.
[keyword] A
keyword enclosed in square brackets is an identifier. This is not
standard SQL. This quoting mechanism is used by MS Access and SQL
Server and is included in SQLite for compatibility.
`keyword` A
keyword enclosed in grave accents (ASCII code 96) is an identifier.
This is not standard SQL. This quoting mechanism is used by MySQL and
is included in SQLite for compatibility.
From SQLite documentation

What does the “&” symbol do in SQL?

What does the “&” symbol do?
select *
from emp
where ename like '&A%';
I infer you are using Oracle RDBMS since EMP.ENAME is from one of the example schemas from Oracle. In Oracle the ampersand "&" can be used as a substitution variable in SQL*Plus (client). See http://oracle-base.com/articles/misc/literals-substitution-variables-and-bind-variables.php#substitution_variables.
99% of the time, you are probably not doing substitution and want a literal ampersand. Such as INSERT INTO sometable VALUES ('Black & Decker'); So you would disable substitution first in SQL*Plus with SET DEFINE OFF.
It doesn't do or mean anything special in SQL string literal. It is just stands for itself; i.e. the ampersand character. So like '&A%' means a string that starts with '&A'.
Apparently (Joshua's answer), the ampersand can have special meaning in Oracle SQLPlus. But that isn't SQL. It is a different language that has SQL syntax embedded in it.

SQL Server edits the table name with dbo as prefix

I have been using SQL Server CE for a while. In that database the table names were like
UserPosts, UserProfile.
But after my upgrade from SQL Server CE to SQL Server the names are edited to dbo.UserPosts, dbo.UserProfile. And also the names of columns are wrapped in square brackets like: [UserProfile].
Why is this bracket used?
Brackets are used to surround names in SQL Server (they server the same purpose as double quotes).
For names that consist of alphanumeric characters and underscore, do not start with a digit, and are not reserved words, the square brackets are not needed. They are typically used for columns that have "irregular" names, such as [Column Name] (note the space) or a reserved word like [from].
When SQL Server generates code, it is overly conservative (in my opinion) about the use of square brackets. It uses them for all column names, table names, and even type names in create table statements. Because I never use "irregular" characters in my names, I find all the brackets to be unnecessary clutter.
The dbo is something called a schema. SQL Server uses a three part naming convention for tables in a database: ... The database name defaults to the current data base, if it is not present. The schema defaults to dbo (or another default schema if that has been changed, which is almost never). And, there is a four part naming convention, where the first part is the server name.