查詢mysql的表結構相關sql

2021-09-02 19:51:09 字數 2049 閱讀 1359

/**檢視表結構**/  

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'/**資料列型別*/  

檢視獲取表內字段注釋:

> show full columns from tablename;

或是 show full fields from tablename;

或是,在元資料的表裡面看

select column_name 列名, data_type 字段型別, column_comment 字段注釋

from information_schema.columns

where table_name = 'companies'##表名

and table_schema = 'testhuicard'##資料庫名

and column_name like 'c_name'##欄位名

2-1檢視表注釋的方法:

> show  create  table  tablename;

2-2獲取整個資料庫的所有表資訊(包含表名,表注釋,表型別等等):

> select table_name, table_type, engine

-> from information_schema.tables

-> where table_schema = 'db5' //table_schema是資料庫名

-> order by table_name desc;

//該語句請求按逆向字母順序列出資料庫db5中的所有表,但僅顯示三種資訊:表名,表型別,以及表引擎。

information_schema是資訊資料庫,其中儲存著關於mysql伺服器所維護的所有其他資料庫的資訊.

> select table_comment from information_schema.tables  where table_name = 'sh_goods' and table_schema = 'sh_shop';//獲取sh_shop 資料庫中 sh_goods 表 的注釋。

2-3獲取表注釋或是

或者使用:show table status;

comment 就是表注釋。

拓展:修改表的注釋:

alter table test1 comment '修改後的表的注釋';

修改欄位的注釋:

alter table test1 modify column field_name int comment '修改後的字段注釋';  

mysql 查詢表結構

檢視表中字段的結構資訊 可以用來檢視表中字段的注釋等,比如 select table name,column name,column comment from information schema.columns where table schema 表所在的庫 and table name 要檢視...

查詢mysql表結構的語句 查詢表結構的slq語句

1.mysql 和 sqlserver 資料庫 檢視表結構 select from information schema.columns where table name 表名 修改字段長度 alter table 表名 alter column 欄位名 字段型別 字段長度 oracle 資料庫 檢...

mysql資料庫 查詢模型 mysql之SQL模型

sql模型 sql mode 通過定義某些規定,限制使用者行為,並定義對應的處理機制。常見的模型 ansi 寬鬆模式,對插入資料進行校驗,如果不符合定義型別或長度,對資料型別調整或截斷儲存,報warning警告。traditional 嚴格模式,當向mysql資料庫插入資料時,進行資料的嚴格校驗,保...