2012-01-09 46 views
1

有人能解釋爲什麼我收到此錯誤:變更表/解鎖

Table 'last' was not locked with LOCK TABLES 

這裏是陸續執行一個查詢:

LOCK TABLES last WRITE; 
DELETE FROM last WHERE id < '30'; 
ALTER TABLE last DROP id; 
ALTER TABLE last ADD COLUMN `id` SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`id`); 

UNLOCK TABLES; 

上線的誤差點,增加了列(id),但是,如果我把解鎖語句之後刪除 - 一切正常,沒有錯誤。是不是真的,我不能最後解鎖一張桌子?它給我的錯誤與其他表,說同樣的事情

+1

一個ALTER TABLE語句自動自動解鎖表 – 2012-01-09 17:02:21

+0

但爲什麼它給出了錯誤然後在第二個ALTER查詢? – 2012-01-09 17:04:40

+0

好的,所以我想要刪除最後一個解鎖語句,我猜? – 2012-01-09 17:10:25

回答

0

http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html「表不是用LOCK TABLES鎖定」:

If you use ALTER TABLE on a locked table, it may become unlocked. For example, if you attempt a second ALTER TABLE operation, the result may be an error Table 'tbl_name' was not locked with LOCK TABLES. To handle this, lock the table again prior to the second alteration. See also Section C.5.7.1, 「Problems with ALTER TABLE」.