MYSQL8-快速生成表结构(用于生成文档)

各种工具都有,没有特别趁手的。不如自己用sql处理。

SELECT column_name AS CODE,
    CASE WHEN column_comment IS NULL OR TRIM(column_comment)='' THEN column_name 
         ELSE 
            CASE WHEN INSTR(column_comment,'-')>0 THEN SUBSTR(column_comment,1,INSTR(column_comment,'-')-1)
                 WHEN INSTR(column_comment,'')>0 THEN SUBSTR(column_comment,1,INSTR(column_comment,'')-1)
                 WHEN INSTR(column_comment,'(')>0 THEN SUBSTR(column_comment,1,INSTR(column_comment,'(')-1)
                 WHEN INSTR(column_comment,';')>0 THEN SUBSTR(column_comment,1,INSTR(column_comment,';')-1)    
                 WHEN INSTR(column_comment,'|')>0 THEN SUBSTR(column_comment,1,INSTR(column_comment,'|')-1)        
                 WHEN INSTR(column_comment,' ')>0 THEN SUBSTR(column_comment,1,INSTR(column_comment,' ')-1)      
                 WHEN INSTR(column_comment,',')>0 THEN SUBSTR(column_comment,1,INSTR(column_comment,',')-1)            
                 ELSE column_comment
             END
     END AS  column_name ,
    column_type, 
   column_comment ,is_nullable FROM information_schema.columns 
   WHERE table_name='xxxx' AND table_schema='xxx' ORDER BY ordinal_position

执行效果如下:

 

posted @ 2022-06-20 11:00  正在战斗中  阅读(256)  评论(0编辑  收藏  举报