문제

I want to generically use any SQL database(I'm using jdbc, it works if the driver and the URL are provided).

It seems, that different DBMS use different quoting for table names.

For example, I have the following in MySQL:

SELECT * FROM `tablename`;

while it is

SELECT * FROM [tablename];

in MS SQL Server.

Is there an "uniform" quoting that all databases support? Or is there a jdbc method that gives me tells me the correct quoting?

도움이 되었습니까?

해결책

The SQL standard prescribes double quotes for quoted identifiers:

SELECT * FROM "tablename"

MySQL and SQL Server can be configured to comply with the standard, while other DBMSes comply out of the box. However, as others suggested in comments, you should avoid using quoted identifiers if possible, because it opens opportunities for bugs and unexpected behaviour in the SQL code.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 dba.stackexchange
scroll top