2016-07-25 117 views
0

我知道我可以通過刪除列評論 alter table tal_name modify column Field Type comment ''
但是,如果我有很多評論刪除,我怎麼能通過SQL腳本來做到這一點?
第一次我想用show full columns from tal_name來獲得完整的信息,所以我可以使用光標刪除評論,但我發現我不能使用show聲明的結果,就像我使用select聲明一樣。
我也不能create viewshow結果。
也許我的想法是錯誤的,那麼有沒有辦法批量刪除評論?
任何幫助表示讚賞。如何批量刪除mysql中的列註釋?

+2

爲什麼?好處在哪裏? – EJP

+0

你可以在一個存儲過程中使用info模式,一個遊標和一個帶有concat字符串和執行的'prepare'來執行 – Drew

+0

好處是,當在server/phpmyadmin版本之間移動腳本時,某些服務器/ pma版本會受到攻擊在運行帶註釋行的腳本時啓動。我們奴隸有一段時間試圖提醒自己。 – Drew

回答

0

當我想你只有這樣做一次,你可以按照以下兩個步驟:

首先執行這個查詢:

select concat('alter table ', '`',table_name,'` ', 
     'modify column `', column_name,'` ', 
     column_type, 
     ifnull(concat(' character set ', character_set_name), ''), 
     ifnull(concat(' collate ', collation_name), ''), 
     if(is_nullable = 'no', ' not null ', ''), 
     if(column_default is null, '', concat(' default ', quote(column_default))), 
     ' ', extra, ';') 
      as column_definition 
from information_schema.columns 
where table_schema like 'db%' 
    and column_comment is not null; 

...上表架構改變的條件你案件。輸出將是每行的SQL語句:

column_definition 
--------------------------------------------------------- 
alter table `tab` modify column `id` int(11) not null auto_increment; 
alter table `tab` modify column `name` varchar(100) not null; 

將SQL語句複製到該輸出中並執行它們。 comment子句的缺失將刪除這些列上的註釋。