1. 程式人生 > >mysql中查看錶結構相關sql

mysql中查看錶結構相關sql

    /**查看錶結構**/  
    desc yourtablename  
    /**檢視建立表語句**/  
    show create table yourtablename  
    /**檢視所有列的資訊**/  
    use information_schema;  
    select * from columns where table_name='yourtablename';  
    /**檢視所有列名的資訊**/  
    use information_schema;  
    select column_name from columns where table_name='yourtablename';  
    /**拼接列名到預定義的sql**/  
    select concat('insert into yourtablename values(',r.column_name) from   
    (select group_concat(column_name) column_name from columns where table_name='yourtablename') r;  
    /**查詢mysql中包含指定列的所有表名稱和註釋**/  
    useinformation_schema;  
    selectdistinctc.table_name,t.TABLE_COMMENTfromcolumnscleftjointablest  
    onc.table_name=t.TABLE_NAME  
    wherec.TABLE_SCHEMA='database'/**資料庫名稱*/  
    andc.COLUMN_NAME='password'/**列名稱*/  
    andc.DATA_TYPE='int'/**資料列型別*/