查詢MySQL資料庫中表結構的幾種方法

2021-09-27 06:47:23 字數 904 閱讀 4726

查詢方法: 

以表『employees』為例子

1.describe(desc)表名 

desc 是 describe的縮寫 

describe用於檢視特定表的詳細設計資訊

desc employees;

或者describe employees;12

32.show columns from 表名

查詢出表的列資訊

show columns from employees;

1方法一和方法二的結果是一樣的 

其中:field:字段表示的是列名

type:字段表示的是列的資料型別

null :字段表示這個列是否能取空值

key :在mysql中key 和index 是一樣的意思,這個key列可能會看到有如下的值:pri(主鍵)、mul(普通的b-tree索引)、uni(唯一索引)

default: 列的預設值

extra :其它資訊12

3456

73.show create table 表名

這個是查詢建表語句

show create table employees;

14.use information_schema;select * from columns where table_name =』表名』;

information_schema資料庫是mysql自帶的,它提供了訪問資料庫元資料的方式。

什麼是元資料呢?

元資料是關於資料的資料,如資料庫名或表名,列的資料型別,或訪問許可權等。有些時候用於表述該資訊的其他術語包括「資料詞典」和「系統目錄」。

use information_schema

select * from columns where table_name ='employees';12

查詢MySQL資料庫中表結構

什麼是表結構?表結構就是定義資料表檔名,確定資料表包含哪些字段,各字段的欄位名 字段型別 及寬度,並將這些資料輸入到計算機當中。查詢方法 以表 employees 為例子 1.describe desc 表名 desc 是 describe的縮寫 describe用於檢視特定表的詳細設計資訊 des...

查詢MySQL資料庫中表結構的幾種方法

什麼是表結構?表結構就是定義資料表檔名,確定資料表包含哪些字段,各字段的欄位名 字段型別 及寬度,並將這些資料輸入到計算機當中。查詢方法 以表 employees 為例子 1.describe desc 表名 desc 是 describe的縮寫 describe用於檢視特定表的詳細設計資訊 des...

查詢資料庫中表的資訊

select 表名 case when a.colorder 1 then d.name else end,表說明 case when a.colorder 1 then isnull f.value,else end,字段序號 a.colorder,欄位名 a.name,標識 case when ...