国产成人精品18p,天天干成人网,无码专区狠狠躁天天躁,美女脱精光隐私扒开免费观看

MySQL追加注釋或者大量修改注釋的方法

發(fā)布時(shí)間:2021-09-27 17:43 來(lái)源:億速云 閱讀:0 作者:chen 欄目: Mysql 歡迎投稿:712375056

這篇文章主要講解了“追加注釋或者大量修改注釋的方法”,文中的講解內容簡(jiǎn)單清晰,易于學(xué)習與理解,下面請大家跟著(zhù)小編的思路慢慢深入,一起來(lái)研究和學(xué)習“MySQL追加注釋或者大量修改注釋的方法”吧!

MySQL 5.6.14

之前一個(gè)項目比較倉促,開(kāi)發(fā)給的建表語(yǔ)句沒(méi)有注釋.
現在要補全注釋信息.
但是MySQL后期追加注釋比較麻煩
需要使用modify語(yǔ)法。

只要不小心寫(xiě)錯一點(diǎn),就可能導致表結構的變更,而不是注釋的變更.

實(shí)驗表如下:

  1. create table t(  

  2.     c1 int primary key auto_increment,  

  3.     c2 char(20) not null default 'c2'  comment 'c2的注釋',  

  4.     c3 date default '2016-01-25' comment 'date類(lèi)型測試',  

  5.     c4 varchar(20) not null default '' ,  

  6.     c5 bigint ,  

  7.     c6 text comment 'text測試',  

  8.     c7 timestamp not null default on update not null default now()  

  9. );  



通過(guò)如下的SQL,解析元數據信息,可以直接顯示modify的內容.
追加或者修改注釋之后,執行語(yǔ)句即可.
這樣可以避免人為的失誤.

  1. SELECT     

  2. concat(    

  3.     'alter table ',     

  4.     table_schema, '.', table_name,     

  5.     ' modify column ', column_name, ' ', column_type, ' ',     

  6.     if(is_nullable = 'YES', ' ', 'not null '),     

  7.     if(column_default IS NULL, '',     

  8.         if(    

  9.             data_type IN ('char', 'varchar')     

  10.             OR     

  11.             data_type IN ('date', 'datetime', 'timestamp') AND column_default != 'CURRENT_TIMESTAMP',     

  12.             concat(' default ''', column_default,''''),     

  13.             concat(' default ', column_default)    

  14.         )    

  15.     ),     

  16.     if(extra is null or extra='','',concat(' ',extra)),  

  17.     ' comment ''', column_comment, ''';'    

  18. ) s    

  19. FROM information_schema.columns    

  20. WHERE table_schema = 'test'    

  21.     AND table_name = 't'   



以實(shí)驗表為例,生成的modify語(yǔ)句如下.

  1. alter table test.t modify column c1 int(11) not null  auto_increment comment '';  

  2. alter table test.t modify column c2 char(20) not null  default 'c2' comment 'c2的注釋';  

  3. alter table test.t modify column c3 date   default '2016-01-25' comment 'date類(lèi)型測試';  

  4. alter table test.t modify column c4 varchar(20) not null  default '' comment '';  

  5. alter table test.t modify column c5 bigint(20)   comment '';  

  6. alter table test.t modify column c6 text   comment 'text測試';  

  7. alter table test.t modify column c7 timestamp not null  default on update '';  

  8. alter table test.t modify column c8 datetime not null  default '';  

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。

αv天堂在线观看免费| 公么大龟弄得我好舒服秀婷视频| 国产午夜福利在线播放 | 亚洲日韩AV无码一区二区三区| 亚洲成AV人片一区二区三区| 日本亚洲欧洲无免费码在线|