mysql 导出表结构

Posted GE12

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql 导出表结构相关的知识,希望对你有一定的参考价值。

-- DECLARE @db="industry_brain" ;
SET @db="ndustry_brain" ;
SET @tableName="dany_tec" ;

SELECT "表名","表描述","","","","","" UNION
SELECT "dwd_cy_nyxx_ys_all" NAME,TABLE_COMMENT,"","","","","" VALUE FROM INFORMATION_SCHEMA.TABLES
where
table_schema =@db
AND
table_name  = @tableName UNION

SELECT "列名", "数据类型","字段类型","长度","是否为空","默认值","备注" UNION
 SELECT COLUMN_NAME 列名,COLUMN_TYPE 数据类型, DATA_TYPE 字段类型,CHARACTER_MAXIMUM_LENGTH 长度,
  IS_NULLABLE 是否为空,COLUMN_DEFAULT 默认值,COLUMN_COMMENT 备注 FROM INFORMATION_SCHEMA.COLUMNS
where
table_schema =@db
AND
table_name  = @tableName



SELECT "库名","表名","列名", "数据类型","是否为空","备注" UNION
 SELECT TABLE_SCHEMA ,TABLE_NAME,COLUMN_NAME 列名,COLUMN_TYPE 数据类型,
  IS_NULLABLE 是否为空,COLUMN_COMMENT 备注 FROM INFORMATION_SCHEMA.COLUMNS
where
table_schema =""
AND
table_name  = ""



 

SELECT b.TABLE_SCHEMA 库名 ,b.TABLE_NAME 表名,a.TABLE_COMMENT 表描述,COLUMN_NAME 列名,b.COLUMN_TYPE 数据类型,
  b.COLUMN_COMMENT 字段描述, a.TABLE_ROWS 行数  from  INFORMATION_SCHEMA.tables a left join INFORMATION_SCHEMA.COLUMNS b
on a.TABLE_SCHEMA=b.TABLE_SCHEMA and a.TABLE_NAME=b.TABLE_NAME
where a.TABLE_ROWS >0 and a.table_schema =""
AND
a.table_name  = ""





-----------------------Oracle ---------------------------------------------------------------------------------




SELECT t3.comments       AS "表注释",
t1.Table_Name       AS "表名称",     
       t1.Column_Name                                AS "字段名称",
       t1.DATA_TYPE || '(' || t1.DATA_LENGTH || ')'  AS "数据类型",
       t1.NullAble                                   AS "是否为空",
       t2.Comments                                   AS "字段注释",
       t1.Data_Default "默认值"
  FROM user_tab_cols t1
  LEFT JOIN user_col_comments t2 
         ON t1.Table_name = t2.Table_name
        AND t1.Column_Name = t2.Column_Name
  LEFT JOIN user_tab_comments t3 
         ON t1.Table_name = t3.Table_name
  LEFT JOIN user_objects t4 
         ON t1.table_name = t4.OBJECT_NAME
  WHERE NOT EXISTS (SELECT t4.Object_Name
          FROM User_objects t4
         WHERE t4.Object_Type = 'TABLE' 
         
           AND t4.Temporary = 'Y'
           AND t4.Object_Name = t1.Table_Name)
           and t1.Table_Name in ('ads_company_info'
            --可以注释掉上面这句
            )        
  ORDER BY t1.Table_Name, t1.Column_ID; 

 

以上是关于mysql 导出表结构的主要内容,如果未能解决你的问题,请参考以下文章

mysql 怎样导出一个表的结构和数据

powerdesider怎样根据mysql已有的表导出结构

navicat怎么导出表结构?mysql用navicat如何导出表结构啊?求解

如何将mysql表结构导出成Excel格式的

如何将mysql表结构导出成Excel格式的

Mysql导出表结构和数据