MySQL查詢資料庫表和資料庫字段

2021-09-23 07:45:42 字數 1451 閱讀 9091

information_schema資訊資料庫

mysql中存在乙個自帶的資料庫information_schema,其中儲存著關於mysql伺服器所維護的所有其他資料庫的資訊。

-- 查詢test_database中的檢視

select

*from information_schema.

tables

where table_schema =

'test_database'

and table_type =

'view'

;-- 查詢test_database中的表

select

*from information_schema.

tables

where table_schema =

'test_database'

and table_type =

'base table'

;-- 查詢test_table表/檢視的表結構

select

column_name as

'列名'

, data_type as

'資料型別'

, column_type as

'資料型別(長度)',if

(column_key=

'pri'

,'√',''

)as'主鍵',if

(column_key=

'mul'

,'√',''

)as'外來鍵',if

(column_key=

'uni'

,'√',''

)as'唯一鍵',if

(is_nullable=

'no'

,'√',''

)as'是否允許非空',if

(extra =

'auto_increment'

,'√',''

)as'是否自增'

, character_maximum_length as

'字元長度'

,

numeric_precision as

'數字長度'

,

numeric_scale as

'小數字數'

,

column_default as

'預設值'

,

column_comment as

'備註'

from

information_schema.

columns

where

table_schema =

'test_database'

and table_name =

'test_table'

;

SQL Server查詢資料庫表和資料庫字段

在sql server中查詢資料庫表和字段的方式可以有三種 方法一 查詢所有表 select from sys.tables 查詢所有列 select from sys.columns 查詢所有擴充套件屬性,我們在設計資料庫表和字段時寫的中文備註等資訊會儲存在這裡 select from sys.e...

mysql庫和表 mysql資料庫和資料表

mysql資料庫可支援要求最苛刻的 web 電子商務和聯機事務處理 oltp 應用程式。它是乙個全面整合 事務安全 符合 acid 的資料庫,具備全面的提交 回滾 崩潰恢復和行級鎖定功能。mysql 憑藉其易用性 擴充套件力和效能,成為全球最受歡迎的開源資料庫。全球許多流量最大的 都依託於mysql...

mysql查詢資料庫表

使用sql語句查詢mysql指定表字段。可以方便整理資料庫表的說明文件。我在工作中整理了部分sql作為記錄。可以用在以後的mysql文件匯出工具裡。以下為具體內容 使用sql查詢指定資料庫表名和表說明。select table name as tablename,table comment as c...