简体   繁体   English

MySQL更改表名大小写

[英]MySQL alters table name case

When I use MySQL Workbench to Forward engineer my model to a work book, it creates a script file with the names of the tables in quotes. 当我使用MySQL Workbench将我的模型转发工程到工作簿时,它会创建一个脚本文件,并在表名中加上引号。 The table names are all in mixed case, but when the script runs, only the very first table is created with mixed case and the rest are created only in lower case. 表名全都是大小写混合的,但是当脚本运行时,只有第一个表是大小写混合的,其余的都是小写的。 The first two tables out of 20+ are shown before: 前面显示了20个以上的前两个表:

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';

CREATE SCHEMA IF NOT EXISTS `CCBPlus` ;
USE `CCBPlus` ;

-- -----------------------------------------------------
-- Table `CCBPlus`.`Contacts`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `CCBPlus`.`Contacts` (
  `ContactId` INT(11) NOT NULL,
  `ContactType` BIT(3) NOT NULL COMMENT 'Contact Type: 0=Individual, 1=Corporate,   2=Family, 3=Branch, 4=Department, 5=Group, 6=Fund/GIC/Bank company',
  `DisplayName` VARCHAR(80) NOT NULL,
  `SearchName` VARCHAR(80) NOT NULL,
  `Prefix` VARCHAR(15) NULL DEFAULT NULL,
  `LastName` VARCHAR(50) NULL,
  `Initials` VARCHAR(10) NULL DEFAULT NULL,
  `FirstName` VARCHAR(40) NULL DEFAULT NULL,
  `Suffix` VARCHAR(10) NULL DEFAULT NULL,
  `OrganizationName` VARCHAR(50) NULL DEFAULT NULL,
  `InCareOf` VARCHAR(80) NULL COMMENT 'If mail is to be sent with the line \"In care of  [X]\"',
  `Birthdate` DATETIME NULL DEFAULT NULL,
  `Deceased` DATETIME NULL,
  `SocialSecurityNumber` VARCHAR(20) NULL DEFAULT NULL,
  `Gender` BIT(1) NULL DEFAULT 0 COMMENT '0=Male,1=Female',
  `CulturePreference` VARCHAR(10) NULL DEFAULT 'EN-CA' COMMENT 'Global Culture variable, e.g. EN-CA or FR-CA or other.',
  `LastMeeting` DATETIME NULL DEFAULT NULL,
  `Hobbies` VARCHAR(100) NULL,
  `Inactive` TINYINT(1) NOT NULL DEFAULT False,
  `Created` DATETIME NOT NULL,
  `LastModified` DATETIME NOT NULL,
  PRIMARY KEY (`ContactId`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COMMENT = 'Stores contact and optionally personal information for other' /* comment truncated */ /* entities. */;

-- -----------------------------------------------------
-- Table `CCBPlus`.`Branches`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `CCBPlus`.`Branches` (
  `BranchID` INT NOT NULL AUTO_INCREMENT,
  `Name` VARCHAR(50) NOT NULL COMMENT 'Unique name of this branch.',
  `Code` VARCHAR(4) NOT NULL COMMENT 'Internal code for the branch number.',
  `BranchContactId` INT NULL COMMENT 'Provides the address and contact information for  the branch.',
  `BranchManagerID` INT NULL COMMENT 'ID of the agent that manages this branch.',
  `PartnerDirectOfficerID` INT NULL COMMENT 'ID of the partner that is responsible for  this branch.',
  `HeadOffice` TINYINT(1) NOT NULL DEFAULT False COMMENT 'True if this branch is the head office.',
  `VirtualBranch` TINYINT(1) NOT NULL DEFAULT False COMMENT 'Indicates that this branch  is used only for organizational purposes and is not a real branch.',
  `Inactive` TINYINT(1) NOT NULL DEFAULT False COMMENT 'True if this branch is no longer in use.',
  PRIMARY KEY (`BranchID`),
  CONSTRAINT `fk_Branch_ContactInfo`
    FOREIGN KEY (`BranchContactId`)
    REFERENCES `CCBPlus`.`Contacts` (`ContactId`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Branch_Manager`
    FOREIGN KEY (`BranchManagerID`)
    REFERENCES `CCBPlus`.`Agents` (`AgentID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Branch_PartnerDirectOfficer`
    FOREIGN KEY (`PartnerDirectOfficerID`)
    REFERENCES `CCBPlus`.`Agents` (`AgentID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
COMMENT = 'Can represent a physical branch office, head office or a vir' /* comment truncated */ /*tual branch for organizational purposes.*/;
...

When the script is executed by MySQL Workbench, everything runs correctly, but I end up with one table with the correct cased: 'Contacts', and everything else with only lower case: 'branches'. 当脚本由MySQL Workbench执行时,一切都可以正确运行,但是最后我得到一张表,其中带有正确的大小写:“ Contacts”,而其他所有表都只有小写:“ branches”。

I have lower_case_table_names = 2. 我有lower_case_table_names = 2。

I am running MySQL Workbench verson 6.0.9.11421 build 1170 with MySQL 5.1.72 Community version. 我正在使用MySQL 5.1.72 Community版本运行MySQL Workbench版本6.0.9.11421 build 1170。

Any help or suggestions would be appreciated. 任何帮助或建议,将不胜感激。

Thanks, Neil 谢谢,尼尔

After reporting this bug to the MySQL developers, they came back with the suggestion that I set the lower case table names to zero: 向MySQL开发人员报告此错误后,他们回来了,建议我将小写表名设置为零:

lower_case_table_names = 0

This fixed the problem, when running on a Windows 7 development platform. 在Windows 7开发平台上运行时,这解决了该问题。 BTW, renaming the tables manually totally screwed both my MySQL Workbench Model and my Entity Framework model. 顺便说一句,手动重命名表完全搞砸了我的MySQL Workbench模型和Entity Framework模型。 I had to resynch the Entity Framework Model with the database and manually match up the datastore tables with my entities again, and then hand-delete the extra tables and connections created. 我必须将实体框架模型与数据库重新同步,然后再次将数据存储表与我的实体进行匹配,然后手动删除创建的多余表和连接。

CREATE TABLE IF NOT EXISTS `CCBPlus`.`Branches` (
.....
REFERENCES `CCBPlus`.`Agents` (`AgentID`) <--- the table `Agents`
                                           --not created before creating this table.
.....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM