1. 程式人生 > >jpa在mysql中自動建立重複表,只是大小寫不同

jpa在mysql中自動建立重複表,只是大小寫不同

參考資料:

http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html

http://www.alberton.info/dbms_identifiers_and_case_sensitivity.html

However, this same statement is permitted on Windows. To avoid problems caused by such differences, it is best to adopt a consistent convention, such as always creating and referring to databases and tables using lowercase names. This convention is recommended for maximum portability and ease of use.

How table and database names are stored on disk and used in MySQL is affected by thelower_case_table_names system variable, which you can set when starting mysqldlower_case_table_namescan take the values shown in the following table. On Unix, the default value of lower_case_table_names is 0. On Windows the default value is 1. On Mac OS X, the default value is 2.

Value Meaning
0 Table and database names are stored on disk using the lettercase specified in the CREATE TABLE orCREATE DATABASE statement. Name comparisons are case sensitive. You should not set this variable to 0 if you are running MySQL on a system that has case-insensitive file names (such as Windows or Mac OS X). If you force this variable to 0 with 
--lower-case-table-names=0
 on a case-insensitive file system and access MyISAM tablenames using different lettercases, index corruption may result.
1 Table names are stored in lowercase on disk and name comparisons are not case sensitive. MySQL converts all table names to lowercase on storage and lookup. This behavior also applies to database names and table aliases.
2 Table and database names are stored on disk using the lettercase specified in the CREATE TABLE orCREATE DATABASE statement, but MySQL converts them to lowercase on lookup. Name comparisons are not case sensitive. This works only on file systems that are not case sensitive! InnoDB table names are stored in lowercase, as for lower_case_table_names=1.

MySQL

Since MySQL stores each table into a file with the same name in the file system, we can expect it to behave differently depending on the OS where it's installed.


On Windows:

-- test table names and case sensitivity
CREATE TABLE TEST_CASE (id INTEGER);   --ok, test_case table created
CREATE TABLE `Test_Case` (id INTEGER); --fails: already exists
CREATE TABLE `test_case` (id INTEGER); --fails: already exists
CREATE TABLE `TEST_CASE` (id INTEGER); --fails: already exists
 
ALTER TABLE TEST_CASE ADD TeSt INTEGER;   --ok, TeSt field created
ALTER TABLE TEST_CASE ADD `TeSt` INTEGER; --fails: already exists
ALTER TABLE TEST_CASE ADD `test` INTEGER; --fails: already exists
ALTER TABLE TEST_CASE ADD `TEST` INTEGER; --fails: already exists
 
INSERT INTO test_case (id) VALUES (1);   --record inserted into test_case table
INSERT INTO `test_case` (id) VALUES (1); --record inserted into test_case table
INSERT INTO `Test_Case` (id) VALUES (1); --record inserted into test_case table
INSERT INTO `TEST_CASE` (id) VALUES (1); --record inserted into test_case table
INSERT INTO `TEST_case` (id) VALUES (1); --record inserted into test_case table

On Unix/Linux:

-- test table names and case sensitivity
CREATE TABLE Test_Case (id INTEGER);   --ok, Test_Case created
CREATE TABLE `Test_Case` (id INTEGER); --fails: already exists
CREATE TABLE `test_case` (id INTEGER); --ok, test_case created
CREATE TABLE `TEST_CASE` (id INTEGER); --ok, TEST_CASE created
 
ALTER TABLE TEST_CASE ADD TeSt INTEGER;   --ok, TeSt field created
ALTER TABLE TEST_CASE ADD `TeSt` INTEGER; --fails: already exists
ALTER TABLE TEST_CASE ADD `test` INTEGER; --fails: already exists
ALTER TABLE TEST_CASE ADD `TEST` INTEGER; --fails: already exists
 
INSERT INTO Test_Case (id) VALUES (1);   --record inserted into Test_Case table
INSERT INTO `test_case` (id) VALUES (1); --record inserted into test_case table
INSERT INTO `Test_Case` (id) VALUES (1); --record inserted into Test_Case table
INSERT INTO `TEST_CASE` (id) VALUES (1); --record inserted into TEST_CASE table
INSERT INTO `TEST_case` (id) VALUES (1); --fails: TEST_case table doesn't exists

Some interesting observations: on Windows, the table name is lowercased if unquoted, while on *nix the case is preserved. That's because of the default value of thelower_case_table_names system variable, which is different on the two systems.
In all the platforms, the case in the field names is preserved, but no two column