mysql數據刪除表與表字段的備注信息


  干了,兄弟們。主體思路是直接手動刪除。。。。。。那是不可能的,全部表的字段總和多達上千可能上萬個字段,手動刪除是不可行的,還是得要用sql語句。

  通過sql語句能查詢數據庫中的全部備注信息,我們可以通過sql查詢備注信息,然后將備注信息拼接成一個修改sql。

SELECT     
concat(    
    'alter table ',     
    table_schema, '.', table_name,     
    ' modify column ', column_name, ' ', column_type, ' ',     
    if(is_nullable = 'YES', ' ', 'not null '),     
    if(column_default IS NULL, '',     
        if(    
            data_type IN ('char', 'varchar')     
            OR     
            data_type IN ('date', 'datetime', 'timestamp') AND column_default != 'CURRENT_TIMESTAMP',     
            concat(' default ''', column_default,''''),     
            concat(' default ', column_default)    
        )    
    ),      
    if(extra is null or extra='','',concat(' ',extra)),
    ' comment ''', ''';'    
) s    
FROM information_schema.columns    
WHERE table_schema = 'esmapweichuangoff'

   備注說明:table_schema 字段存儲的是數據庫名稱,如果需要指定特定的表加上  and table_name=''。

 

  在數據庫鏈接工具中執行上面sql,就能得到每一個備注信息對應的修改語句了。如下圖:  

  

  將執行結果導出:

  

  將導出的結果放在數據庫鏈接工具中執行。

 完。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM