更新查询在php循环中触发时被锁定

时间:2014-09-16 04:27:42

标签: php mysql

当我更新表记录并且该查询在PHP循环中运行时,我得到表锁定问题并且查询没有响应。

这是我的cstcustomers平板电脑:

 CREATE TABLE `tblcstcustomers` (                              
                       `CustomerId` INT(10) NOT NULL AUTO_INCREMENT,               
                       `CustomerCode` VARCHAR(255) NOT NULL,                       
                       `CustomerName` VARCHAR(255) NOT NULL,                       
                       `CustomerPassword` VARCHAR(200) DEFAULT NULL,               
                       `ClientId` INT(11) DEFAULT NULL,                            
                       `TeamID` INT(10) NOT NULL DEFAULT '0',                      
                       `ExcludeFromReports` ENUM('Yes','No') DEFAULT NULL,         
                       `NumEvents` INT(10) DEFAULT NULL,                           
                       `isDrillDownReportAllowed` INT(1) DEFAULT '0',              
                       `Status` INT(1) DEFAULT '0',                                
                       `AddedBy` VARCHAR(255) DEFAULT NULL,                        
                       `AddedDate` DATETIME DEFAULT NULL,                          
                       `ModifiedBy` VARCHAR(255) DEFAULT NULL,                     
                       `ModifiedDate` DATE DEFAULT NULL,                           
                       `Satisfication` FLOAT DEFAULT NULL,                         
                       `RedSurvey` INT(10) DEFAULT NULL,                           
                       `GreenSurvey` INT(10) DEFAULT NULL,                         
                       `AmberSurvey` INT(10) DEFAULT NULL,                         
                       `EventCount` INT(10) DEFAULT '0',                           
                       `GroupParentId` INT(10) DEFAULT '0',                        
                       `GroupName` VARCHAR(255) DEFAULT NULL,                      
                       `GroupCode` VARCHAR(255) DEFAULT NULL,                      
                       `IsGroup` TINYINT(1) DEFAULT '0',                           
                       `IsDeleted` ENUM('Yes','No') DEFAULT 'No',                  
                       `CodeRedEmailName` VARCHAR(255) DEFAULT NULL,               
                       `CodeRedEmail` TEXT,                                        
                       `CodeRedEmailCC` TEXT,                                      
                       `EscalationEmailName` VARCHAR(255) DEFAULT NULL,            
                       `EscalationEmail` TEXT,                                     
                       `EscalationEmailcc` TEXT,                                   
                       PRIMARY KEY (`CustomerId`,`CustomerCode`),                  
                       UNIQUE KEY `CustomerId` (`CustomerId`)                      
                     ) ENGINE=MYISAM AUTO_INCREMENT=126238 DEFAULT CHARSET=latin1;

这里是我的supsuppliers表:

                   CREATE TABLE `tblsupsuppliers` (                              
                   `SupplierId` INT(10) NOT NULL AUTO_INCREMENT,               
                   `SupplierTypeId` INT(11) DEFAULT NULL,                      
                   `SupplierCode` VARCHAR(255) NOT NULL,                       
                   `GroupName` VARCHAR(255) DEFAULT NULL,                      
                   `GroupCode` VARCHAR(255) DEFAULT NULL,                      
                   `IsGroup` TINYINT(1) DEFAULT '0',                           
                   `SupplierName` VARCHAR(255) DEFAULT NULL,                   
                   `SupplierPassword` VARCHAR(200) DEFAULT NULL,               
                   `ClientId` INT(11) DEFAULT NULL,                            
                   `ExcludeFromSummary` ENUM('Yes','No') DEFAULT NULL,         
                   `ExcludeFromCustomReport` ENUM('Yes','No') DEFAULT NULL,    
                   `Status` INT(1) DEFAULT '0',                                
                   `AddedBy` VARCHAR(50) DEFAULT NULL,                         
                   `AddedDate` DATETIME DEFAULT NULL,                          
                   `ModifiedBy` VARCHAR(50) DEFAULT NULL,                      
                   `ModifiedDate` DATETIME DEFAULT NULL,                       
                   `Satisfication` FLOAT DEFAULT NULL,                         
                   `RedSurvey` INT(10) DEFAULT NULL,                           
                   `GreenSurvey` INT(10) DEFAULT NULL,                         
                   `AmberSurvey` INT(10) DEFAULT NULL,                         
                   `FranchiseId` INT(10) NOT NULL DEFAULT '0',                 
                   `GroupParentId` INT(10) DEFAULT '0',                        
                   `EventCount` INT(10) DEFAULT '0',                           
                   `IsDeleted` ENUM('Yes','No') DEFAULT 'No',                  
                   `SupplierBrand` VARCHAR(255) DEFAULT NULL,                  
                   PRIMARY KEY (`SupplierId`),                                 
                   KEY `ClientId` (`ClientId`),                                
                   KEY `GroupParentId` (`GroupParentId`),                      
                   KEY `SupplierName` (`SupplierName`),                        
                   KEY `FranchiseId` (`FranchiseId`)                           
                 ) ENGINE=MYISAM AUTO_INCREMENT=307490 DEFAULT CHARSET=latin1;

以下查询在循环中运行:

update tblsupsuppliers sup, tblcstcustomers cus
set cus.ExcludeFromReports = 'No', sup.ExcludeFromSummary  = 'No',
sup.ExcludeFromCustomReport = 'No' 
where cus.ClientId = '71' and sup.ClientId ='71';

1 个答案:

答案 0 :(得分:2)

您无法同时使用transaction更新两个表,以确保以原子方式处理两个UPDATE语句。

BEGIN TRANSACTION

UPDATE Table1 WITH SQL


UPDATE Table2 WITH SQL


COMMIT