-2

我正在使用 MySQL Workbench 并尝试更改列名。该列是许多外键的一部分。

我在想这就是导致错误的原因。我正在尝试重命名strCustomerCodestrCustomerCodeNEW

代码:

ALTER TABLE `Check4It_MainDB`.`tbl_000_010_MAIN_REPORT_INFO` 
CHANGE COLUMN `strCustomerCode` `strCustomerCodeNEW` VARCHAR(255) 
    CHARACTER SET 'utf8' NOT NULL ;

这是错误:

错误 1025:将“./Check4It_MainDB/#sql-b6a_4a5”重命名为“./Check4It_MainDB/tbl_000_010_MAIN_REPORT_INFO”时出错(错误号:150)

SQL 语句:

ALTER TABLE `Check4It_MainDB`.`tbl_000_010_MAIN_REPORT_INFO` 
CHANGE COLUMN `strCustomerCode` `strCustomerCodeNEW` VARCHAR(255) 
    CHARACTER SET 'utf8' NOT NULL

错误:运行故障回复脚本时出错。详细信息如下
错误 1046:未选择数据库

SQL 语句:

CREATE TABLE `tbl_000_010_MAIN_REPORT_INFO` (
    `strCustomerCode` varchar(255) CHARACTER SET utf8 NOT NULL'
    `strPasscodeAdmin` varchar(255) CHARACTER SET utf8 NOT NULL,
    `strPasscodeClient` varchar(255) CHARACTER SET utf8 NOT NULL,
    `idMainReport_ID` int(11) NOT NULL AUTO_INCREMENT,
    `lngProcedure_ID` int(11) DEFAULT NULL,
    `strHardDriveID` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
    `lngInspector_01_ID` int(11) DEFAULT NULL,
    `lngInspector_02_ID` int(11) DEFAULT NULL,
    `lngShift_ID` int(11) DEFAULT NULL,
    `lngUnit_ID` int(11) DEFAULT NULL,
    `dtmReportCreated` datetime DEFAULT NULL,
    `dtmReportSubmitted` datetime DEFAULT NULL,
    `bolCompleted` bit(1) DEFAULT b'0',
    `memReportComments` longtext CHARACTER SET utf8,
    `strTextMessage` varchar(160) CHARACTER SET utf8 DEFAULT NULL,
    `bolTextMessageOn` bit(1) DEFAULT b'0',
    `bolTextSent` bit(1) DEFAULT b'0',
    `bolReportEmailSent` bit(1) DEFAULT b'0',
    `bolCompletionEmailSent` bit(1) DEFAULT b'0',
    `bolReportPostedToCloud` bit(1) DEFAULT b'0',
    `strComputerName` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
    `strUserLogin` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
    `strUserVersionNUmber` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
    `bolImportedReport` bit(1) DEFAULT NULL,
    `bolTestReport` bit(1) DEFAULT b'0',
    `strOSVersion` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
    `strWindowsVersion` varchar(255) CHARACTER SET utf8 DEFAULT NULL,

PRIMARY KEY (`idMainReport_ID`, `strCustomerCode`, `strPasscodeAdmin`, `strPasscodeClient`),

KEY `idMainTest_ID1` (`lngProcedure_ID`),
KEY `idProcedure_ID` (`idMainReport_ID`),
KEY `lngMemebrInfoID` (`lngInspector_01_ID`),
KEY `lngShift_ID` (`lngShift_ID`),
KEY `lngUnit_ID` (`lngUnit_ID`),
KEY `strHardDriveID` (`strHardDriveID`),
KEY `strPasscodeClient` (`strPasscodeClient`),
KEY `tbl_000_010_MAIN_REPORT_INFOstrPasscodeAdmin` (`strPasscodeAdmin`),
KEY `tblREF_InspectorInfotbl_000_010_MAIN_REPORT_INFO` (`lngInspector_01_ID`,`strCustomerCode`),
KEY `strPasscodeAdmin` (`strPasscodeAdmin`,`strCustomerCode`,`lngProcedure_ID`),
KEY `idMainReport_ID` (`idMainReport_ID`,`strPasscodeAdmin`,`strCustomerCode`,`strPasscodeClient`),
KEY `strCustomerCode` (`strCustomerCode`,`lngInspector_02_ID`),
KEY `lngShift_ID_2` (`lngShift_ID`,`strCustomerCode`),
KEY `strCustomerCode_2` (`strCustomerCode`,`lngUnit_ID`),

CONSTRAINT `FK_WithShiftID` FOREIGN KEY (`lngShift_ID`) REFERENCES `tblREF_ShiftID` (`idShift_ID`) 
    ON DELETE CASCADE ON UPDATE CASCADE) 
ENGINE=InnoDB AUTO_INCREMENT=63 DEFAULT CHARSET=latin1
4

1 回答 1

0

你的错误说

错误 1046:未选择数据库

这是因为没有选择数据库。sql server 应该如何知道要查找表的数据库Check4It_MainDB

要在工作台中执行此操作,请右键单击数据库并选择Set As Default Schema. 现在,这将使任何未明确提供数据库的脚本使用您指定的数据库。

更好的方法是将其添加到所有脚本的顶部:

use MyDatabaseName;

此后执行的任何代码都将使用该数据库,除非再次明确定义。

于 2013-09-19T17:12:21.343 回答